INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012.

Slides:



Advertisements
Similar presentations
1 Today’s Class  Relational Model  SQL CS F212 Database Systems.
Advertisements

INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012.
E-R Diagram for a Banking Enterprise
Formal Relational Query Languages Chapter 6
Introduction to SQL Chapter 3 [1 of 2]
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Ordering the Display of Tuples List in alphabetic order the names of all customers having.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Aandachtspunten Deadlines – alles op tijd inleveren! n Lees goed wat van je verwacht wordt!
SQL By: Toan Nguyen. Download Download the software at During the installation –Skip sign up for fast installation.
SQL Overview Data Definition Basic Queries Set Operations Null Values Aggregate Functions Nested Subqueries Modification of the Database.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
SQL Operations Aggregate Functions Having Clause Database Access Layer A2 Teacher Up skilling LECTURE 5.
Chapter 3: SQL Data Definition Language Data Definition Language Basic Structure of SQL Basic Structure of SQL Set Operations Set Operations Aggregate.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
SQL. Basic Structure SQL is based on set and relational operations with certain modifications and enhancements A typical SQL query has the form: select.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Chapter 3 Introduction to SQL Yonsei University 1 st Semester, 2015 Sanghyun Park.
Lecture 6 Structured Query Language SQL Lecture 6 Structured Query Language SQL Instructor: Haya Sammaneh.
CSc-340 2b1 Introduction to SQL Chapter 3 [2 of 2] Null Values Aggregate Functions Nested Subqueries Modification of the Database.
Advanced SQL Murat Kantarcioglu Adapted from Silberchatz et al. slides.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
1 CS 430 Database Theory Winter 2005 Lecture 12: SQL DML - SELECT.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
Chapter 6: Formal Relational Query Languages. 6.2 Chapter 6: Formal Relational Query Languages Relational Algebra Tuple Relational Calculus Domain Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
INTRODUCTION TO SQL Database System Concepts. Agenda Overview of the SQL Query Language Data Definition Basic Query Structure Additional Basic Operations.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Chapter 3: Introduction to SQL
Advanced Relational Algebra & SQL (Part1 )
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module A: Formal Relational.
Chapter 5-1: Introduction to SQL. 2 Overview of the SQL Query Language Data Definition Basic Query Structure Additional Basic Operations Set Operations.
Database System Concepts, 6 th Ed. Chapter 6: Formal Relational Query Languages.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Chapter 3 Introduction to SQL
Chapter 3 Introduction to SQL(2)
Database Systems SQL cont. Relational algebra
Introduction to SQL.
Chapter 3 Introduction to SQL(3)
Chapter 3: Introduction to SQL
Chapter 6: Formal Relational Query Languages
SQL: Structured Query Language DML- Queries Lecturer: Dr Pavle Mogin
Database Systems Relational algebra SQL cont.
Chapter 3: Introduction to SQL
Chapter 3: Introduction to SQL
Chapter 3: Introduction to SQL
Chapter 6: Formal Relational Query Languages
Chapter 3: Introduction to SQL
Chapter 2: Intro to Relational Model
Chapter 6: Formal Relational Query Languages
Chapter 3: Introduction to SQL
Lecture 2 Relational Database
Lecture 3 Structure Query Language
Presentation transcript:

INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012

Lecture Overview  A few SQL basic odds & ends  Set Operations  Dealing with nulls

Renaming  Attributes and relations can be renamed for utility and cleverness:  SELECT ID, name, salary/12 AS monthly_salary FROM instructor  Find the names of all instructors who have a higher salary than some instructor in ‘Comp. Sci’.  SELECT DISTINCT T. name FROM instructor AS T, instructor AS S WHERE T.salary > S.salary AND S.dept_name = ‘Comp. Sci.’

Ordering  List in alphabetic order the names of all instructors SELECT DISTINCT name FROM instructor ORDER BY name  We may specify desc for descending order or asc for ascending order, for each attribute; ascending order is the default.  Example: ORDER BY name DESC  Can sort on multiple attributes  Example: ORDER BY dept_name ASC, name DESC

Practice Query 1: Join with Problems  Find the ID’s of all students who were taught by an instructor named Einstein. Remove duplicates in the result.

Textbook University Schema Diagram

Set Operations  Remember, a relation is theoretically a SET (as in discrete math) of TUPLES  Union, Intersection, Set-Difference  Used to combine two queries that have IDENTICAL ATTRUBUTE SETS!  Example sets:  All course ID’s for courses taught in Fall 2009  All course ID’s for courses taught in Spring 2010

Union Operation  Combines result of two queries, eliminates duplicates:  Find course ID’s for courses that ran in Fall 2009 or in Spring 2010 (select course_id from section where sem = ‘Fall’ and year = 2009) union (select course_id from section where sem = ‘Spring’ and year = 2010)

Intersect Operation  Finds all non-duplicate tuples in common between two queries  Find courses that ran in both Fall 2009 and Spring 2010 (select course_id from section where sem = ‘Fall’ and year = 2009) intersect (select course_id from section where sem = ‘Spring’ and year = 2010)

Except Operation  EXCEPT keyword does set-difference: gives all tuples in the first query, but removes anything that appears in the second  Probably the most-used of the three operations because a boolean version is tricky  Find courses that ran in Fall 2009 but not in Spring 2010 (select course_id from section where sem = ‘Fall’ and year = 2009) except (select course_id from section where sem = ‘Spring’ and year = 2010)

Duplicates in Set Operations  To retain all duplicates use the corresponding multiset versions union all, intersect all and except all. Suppose a tuple occurs m times in r and n times in s, then, it occurs:  m + n times in r union all s  min(m,n) times in r intersect all s  max(0, m – n) times in r except all s

Null Values  It is possible for tuples to have a null value, denoted by null, for some of their attributes  null signifies an unknown value or that a value does not exist.  The result of any arithmetic expression involving null is null  Example: 5 + null evaluates as null  The predicate is null can be used to check for null values.  Example: Find all instructors whose salary is null. select name from instructor where salary is null  can also use is not null, which can be very useful:  Example: Find all of a student’s grades select takes.* from students natural join takes where grade is not null

Null Values and Three Valued Logic  Any comparison with null returns unknown  Example: 5 null or null = null  Three-valued logic using the truth value unknown:  OR: (unknown or true) = true, (unknown or false) = unknown (unknown or unknown) = unknown  AND: (true and unknown) = unknown, (false and unknown) = false, (unknown and unknown) = unknown  NOT: (not unknown) = unknown  “P is unknown” evaluates to true if predicate P evaluates to unknown  Result of where clause predicate is treated as false if it evaluates to unknown

Set Operations Practice  Can we come up with our own examples?