Database Technology. Topic 2: Relational Databases and SQL. Olaf Hartig.

Size: px
Start display at page:

Download "Database Technology. Topic 2: Relational Databases and SQL. Olaf Hartig."

Transcription

1 Topic 2: Relational Databases and SQL Olaf Hartig

2 Relational Data Model

3 Recall: DB Design Process 3

4 Relational Model Concepts Relational database: represent data as a collection of relations Think of a relation as a table of values Each row (tuple) represents a record of related data values Facts that typically correspond to a real-world entity or relationship Each column (attribute) holds a corresponding value for each row Columns associated with a data type (domain) Each column header: attribute name 4

5 Relational Model Concepts (cont'd) Relational database: represent data as a collection of relations Think of a relation as a table of values Schema describes the relation Relation name, attribute names and domains Integrity constraints Instance denotes the current contents of the relation (also called state) Set of tuples

6 Domains Domain is a set of atomic values { 0, 1, 2, } { Jo Smith, Dana Jones, Ashley Wong, Y. K. Lee, } Atomic: Each value indivisible Domains specified by data type rather than by enumeration Integer, string, date, real, etc. Can be specified by format e.g., (ddd)ddd-dddd for phone numbers (where d represents a digit) 6

7 Schemas and Attributes Relation schema A relation name R and a list of attributes A1, A2,..., An Denoted by R(A1, A2,..., An) Attribute Ai Name of a role in the relation schema R Associated with a domain dom(ai) Attribute names do not repeat within a relation schema, but domains can repeat Degree (or arity) of a relation Number of attributes n in its relation schema 7

8 NULL Values Each domain may be augmented with a special value called NULL Represent the values of attributes that may be unknown or may not apply to a tuple If an attribute of a tuple is NULL, we cannot make any assumption about the value for that attribute (for that tuple) Interpretations for NULL values Nothing is known about the value Value exists but is (currently) not available Value undefined (i.e., attribute does not apply to this tuple) For instance, Ashley s telephone number is NULL could mean Ashley doesn t have a phone Ashley has a phone but we don t know the number (perhaps withheld) Ashley has a phone that has no number 8

9 Integrity Constraints

10 What are Integrity Constraints? Constraints are restrictions on the permitted values in a DB state Derived from the rules in the miniworld that the DB represents 1. Inherent model-based constraints (also called implicit constraints) Inherent in the data model e.g., duplicate tuples are not allowed in a relation 2. Schema-based constraints (also called explicit constraints) Can be directly expressed in schemas of the data model e.g., films have only one director Our focus here 3. Application-based (also semantic constraints or business rules) Not directly expressed in schemas Expressed and enforced by application program e.g., this year s salary increase can be no more than last year s 12

11 Key Constraints Uniqueness constraints on tuples Key of a relation R is a set K of attributes of R that has two properties: 1. Uniqueness: No two distinct tuples have the same values across all attributes in K (i.e., it is a superkey) 2. Minimality: No subset of K has the uniqueness property Superkey: set of attributes that has the uniqueness property (but that is not necessarily minimal) Keys declared as part of the schema of a relation Uniqueness must hold in all valid states Serve as a constraint on updates 13

12 Key Constraints (cont'd) Candidate key: If there is more than one key in a relation, every key is called a candidate key Primary key: a particular candidate key is chosen as the primary Diagrammatically, underline its attribute(s) Tuples cannot have NULL for any primary key attribute Other candidate keys are designated as unique Non-NULL values cannot repeat, but values may be NULL 14

13 Other Integrity Constraints Entity integrity constraint: No primary key value can be NULL Domain constraint: declared by specifying the datatype of attributes Referential integrity constraint Specified between two relations Allows tuples in one relation to refer to tuples in another Maintains consistency among tuples in two relations Foreign key rules: Let PK be the primary key in a relation R1 (i.e., set of attributes in its relational schema declared to be primary key) Let FK be a set of attributes for another relation R2 The attribute(s) FK have the same domain(s) as the attribute(s) PK Value of FK in a tuple t2 of the current state of R2 either occurs as a value of PK for some tuple t1 in the current state of R1 or it is NULL 1

14 Diagramming Referential Constraints Show each relational schema Underline primary key attributes in each Directed arc from each foreign key to the relation it references 16

15 SQL

16 Structured Query Language Declarative language (what data to get, not how) Considered one of the major reasons for the commercial success of relational databases Statements for data definitions, queries, and updates Both DDL and DML Terminology: Relational Model SQL relation table tuple row attribute column Syntax notes: Some interfaces require each statement to end with a semicolon SQL is not case-sensitive 19

17 SQL DDL

18 Creating Tables CREATE TABLE <tablename> ( <colname> <datatype> [<constraint>],, [<constraint>], ); Data types: integer, decimal, number, varchar, char, etc. Constraints: not, primary key, foreign key, unique, etc. 21

19 Creating Tables (Example) CREATE TABLE WORKS_ON ( ESSN integer, PNO integer, HOURS decimal(3,1), constraint pk_workson primary key (ESSN, PNO), constraint fk_works_emp FOREIGN KEY (ESSN) references EMPLOYEE(SSN), constraint fk_works_proj FOREIGN KEY (PNO) references PROJECT(PNUMBER) ); 22

20 Modifying Table Definitions Add, delete, and modify columns and constraints ALTER TABLE EMPLOYEE ADD COLUMN JOB VARCHAR(12); ALTER TABLE EMPLOYEE DROP COLUMN ADDRESS CASCADE; ALTER TABLE WORKS_ON DROP FOREIGN KEY fk_works_emp; ALTER TABLE WORKS_ON ADD CONSTRAINT fk_works_emp FOREIGN KEY (ESSN) REFERENCES EMPLOYEE(SSN); Delete a table and its definition DROP TABLE EMPLOYEE; 23

21 SQL Queries

22 Basic SQL Retrieval Queries All retrievals use SELECT statement: SELECT <return list> FROM <table list> [ WHERE <condition> ] ; where <return list> is a list of column names (or expressions) whose values are to be retrieved <table list> is a list of table names required to process the query <condition> is a Boolean expression that identifies the tuples to be retrieved by the query (if no WHERE clause, all tuples to be retrieved) 2

23 Example SELECT title, year, genre FROM Film WHERE director = 'Steven Spielberg' 1. Start with the relation named in the FROM clause 2. Consider each tuple one after the other, eliminating those that do not satisfy the WHERE clause 3. For each remaining tuple, create a return tuple with columns for each expression (column name) in the SELECT clause Film title The Company Men Lincoln genre drama biography year director John Wells Steven Spielberg minutes 104 gross 1,000,000 4,439,063 6,000, ,408,467 66,000,000 79,883,39 44,00,000 13,178,21 10 War Horse drama 2011 Steven Spielberg 146 Argo drama 2012 Ben Affleck 120 budget 26

24 All Attributes List all information about the employees of department. SELECT FNAME, MINIT, LNAME, SSN, BDATE, ADDRESS, SEX, SALARY, SUPERSSN, DNO FROM EMPLOYEE WHERE DNO = ; or SELECT * FROM EMPLOYEE WHERE DNO = ; Comparison operators {=, <>, >, =>, etc.} 27

25 Logical Operators List the last name, birth date and address for all employees whose name is `Alicia J. Zelaya SELECT LNAME, BDATE, ADDRESS FROM EMPLOYEE WHERE FNAME = Alicia AND MINIT = J AND LNAME = Zelaya ; Logical operators {and, or, not} 28

26 Pattern Matching in Strings List the birth date and address for all employees whose last name contains the substring aya SELECT BDATE, ADDRESS FROM EMPLOYEE WHERE LNAME LIKE %aya% ; LIKE comparison operator % represents 0 or more characters _ represents a single character 29

27 NULLs List all employees that do not have a boss. SELECT FNAME, LNAME FROM EMPLOYEE WHERE SUPERSSN IS NULL; SUPERSSN = NULL and SUPERSSN <> NULL will not return any matching tuples, because NULL is incomparable to any value, including another NULL 30

28 Tables as Sets List all salaries: SELECT SALARY FROM EMPLOYEE; SALARY SQL considers a table as a multi-set (bag), i.e. tuples may occur more than once in a table This is different from the relational data model Why? Removing duplicates is expensive User may want information about duplicates Aggregation operators (e.g., sum) 31

29 Removing Duplicates List all salaries: SELECT SALARY FROM EMPLOYEE; List all salaries without duplicates SELECT DISTINCT SALARY FROM EMPLOYEE; SALARY SALARY

30 Set Operations Duplicate tuples are removed. Queries can be combined by set operations: UNION, INTERSECT, EXCEPT (MySQL only supports UNION) Retrieve the first names of all people in the database. E D SELECT FNAME FROM EMPLOYEE UNION SELECT DEPENDENT_NAME FROM DEPENDENT; Which department managers have dependents? Show their SSN. SELECT MGRSSN FROM DEPARTMENT INTERSECT SELECT ESSN FROM DEPENDENT; M DE 33

31 Join: Cartesian Product List all employees and the names of their departments. SELECT LNAME, DNAME FROM EMPLOYEE, DEPARTMENT; EMPLOYEE LNAME Smith Wong Zelaya Wallace Narayan English Jabbar Borg DNO DEPARTMENT DNAME Research Administration Headquarters DNUM 4 1 LNAME Smith Wong Zelaya Wallace Narayan English Jabbar Borg Smith Wong Zelaya Wallace Narayan English Jabbar Borg Smith Wong Zelaya Wallace Narayan English Jabbar Borg DNAME Research Research Research Research Research Research Research Research Administration Administration Administration Administration Administration Administration Administration Administration Headquarters Headquarters Headquarters Headquarters Headquarters Headquarters Headquarters Headquarters 34

32 Join: Equijoin Foreign key in EMPLOYEE List all employees and the names of their departments. SELECT LNAME, DNAME FROM EMPLOYEE, DEPARTMENT WHERE DNO = DNUM; Equijoin EMPLOYEE LNAME Smith Wong Zelaya Wallace Narayan English Jabbar Borg DNO DEPARTMENT DNAME DNUM Research Administration Headquarters 4 1 Cartesian product Primary key in DEPARTMENT LNAME DNO DNAME Smith Wong Zelaya Wallace Narayan English Jabbar Borg Smith Wong Zelaya Wallace Narayan English Jabbar Borg Smith Wong Zelaya Wallace Narayan English Jabbar Borg Research Research Research Research Research Research Research Research Administration Administration Administration Administration Administration Administration Administration Administration Headquarters Headquarters Headquarters Headquarters Headquarters Headquarters Headquarters Headquarters DNUM

33 Inner Join List all employees and the names of their departments. SELECT LNAME, DNAME FROM EMPLOYEE, DEPARTMENT WHERE DNO = DNUM; As an alternative, the join condition may be given in the FROM clause by using the keywords INNER JOIN and ON as follows: SELECT LNAME, DNAME FROM EMPLOYEE INNER JOIN DEPARTMENT ON DNO = DNUM; 36

34 Ambiguous Names: Aliasing What if the same attribute name is used in different relations? No alias Whole name SELECT EMPLOYEE.NAME, DEPARTMENT.NAME SELECT NAME, NAME FROM EMPLOYEE, DEPARTMENT WHERE DNO=DNUM; FROM EMPLOYEE, DEPARTMENT WHERE EMPLOYEE.DNO=DEPARTMENT.DNUM; Alias SELECT E.NAME, D.NAME FROM EMPLOYEE E, DEPARTMENT D WHERE E.DNO=D.DNUM; 37

35 Self-Join List the last name for all employees together with the last names of their bosses SELECT E.LNAME AS Employee, S.LNAME AS Boss FROM EMPLOYEE E, EMPLOYEE S WHERE E.SUPERSSN = S.SSN; Employee Boss Smith Wong Zelaya Wallace Narayan English Jabbar Wong Borg Wallace Borg Wong Wong Wallace 38

36 Self-Joins may also be written as Inner Join List the last name for all employees together with the last names of their bosses SELECT E.LNAME AS Employee, S.LNAME AS Boss FROM EMPLOYEE E, EMPLOYEE S WHERE E.SUPERSSN = S.SSN; Employee Boss Smith Wong Zelaya Wallace Narayan English Jabbar SELECT E.LNAME Employee, S.LNAME Boss FROM EMPLOYEE E INNER JOIN EMPLOYEE S ON E.SUPERSSN = S.SSN; Wong Borg Wallace Borg Wong Wong Wallace 39

37 Left Outer Join Every tuple in left table appears in result If there exist matching tuples in right table, works like inner join If no matching tuple in right table, one tuple in result with left tuple values padded with NULL values for columns of right table Customer custid name Lee Willis Smith Ng Harrison address 633 S. First 41 King 213 Main Queen N. 808 Main Sale phone saleid A17 B823 B219 C41 X00 date Dec Dec 9 Dec 1 Dec 23 Dec custid NULL SELECT * FROM Customer LEFT JOIN Sale ON Customer.custid = Sale.custid Customer.custid name Lee Willis Willis Smith Ng Harrison address phone 633 S. First King King Main Queen N Main Databases Topic 2: Relational and SQL saleid date Sale.custid C41 A17 B219 NULL B823 NULL 1 Dec Dec 9 Dec NULL Dec NULL NULL 1697 NULL 40

38 Joins Revisited A Cartesian product SELECT * FROM a, b; A1 A2 100 B B1 B2 A 100 W B 200 X A2 A1 B1 B2 300 C Y A W D Z B 100 W C W D 100 W A X B 200 X C X D 200 X A 100 Y B Y C 300 Y D Y A 100 Z B Z C 300 D Equijoin, inner join SELECT * from A, B WHERE A1=B1; A2 A1 B1 B2 A W Thetajoin SELECT * from A, B WHERE A1>B1; A2 A1 B1 B2 Z C W Z C X 41

39 Joins Revisited (cont'd) A Right outer join SELECT * FROM A RIGHT JOIN B on A1=B1; A1 A2 100 B B1 B2 A 100 W B 200 X A2 A1 B1 B2 300 C Y A W D Z 200 X Y Z Full outer join ( union of right+left) SELECT * FROM A FULL JOIN b on A1=B1; Left outer join SELECT * FROM A LEFT JOIN B on A1=B1; A2 A1 B1 B2 A W C 300 B D A2 A1 B1 B2 A W 200 X Y Z C 300 B D 42

40 Subqueries List all employees that do not have any project assignment with more than 10 hours SELECT LNAME FROM EMPLOYEE, WORKS_ON WHERE SSN = ESSN AND HOURS <= 10.0; {>, >=, <, <=, <>} + {ANY, SOME, ALL} SELECT LNAME FROM EMPLOYEE WHERE SSN NOT IN (SELECT ESSN FROM WORKS_ON WHERE HOURS > 10.0); Or EXISTS SELECT LNAME FROM EMPLOYEE WHERE NOT EXISTS (SELECT * FROM WORKS_ON WHERE SSN = ESSN AND HOURS > 10.0); 43

41 Quiz Country Code Name ismemb er Country Organization Consider the following two SQL queries: SELECT Name FROM Country WHERE Code IN ( SELECT Country FROM IsMember WHERE Organization = 'EU' ); SELECT Name FROM Country, IsMember WHERE Code = Country AND Organization = 'EU'; Are these queries equivalent? (yes) (no) 4

42 Additional Features

43 Extended SELECT Syntax SELECT <attribute-list and function-list> FROM <table-list> [ WHERE <condition> ] [ GROUP BY <grouping attribute-list>] [ HAVING <group condition> ] [ ORDER BY <attribute-list> ]; 47

44 Aggregate Functions Used to accumulate information from multiple tuples, forming a single-tuple summary Built-in aggregate functions: SUM, MAX, MIN, AVG, COUNT Example: What is the average budget of all movies? SELECT AVG(budget) FROM Film; Used in the SELECT clause and the HAVING clause Hence, cannot be used in the WHERE clause! NULL values are not considered in the computations; e.g.,: NULL AVG: 48

45 Aggregate Functions (cont'd) Example How many movies were directed by Steven Spielberg? SELECT COUNT(*) FROM Film WHERE director='steven Spielberg'; All tuples in the result are counted, with duplicates! i.e., COUNT(title) or COUNT(director) give same result COUNT(DISTINCT year) would include each year only once 49

46 Grouping Before Aggregation How can we answer a query such as How many films were directed by each director after 2001? Need to produce a result with one tuple per director 1.Partition relation into subsets based on grouping column(s) 2.Apply aggregate function to each such group independently 3.Produce one tuple per group 0

47 Grouping Before Aggregation How can we answer a query such as How many films were directed by each director after 2001? GROUP BY clause to specify grouping attributes SELECT director, COUNT(*) FROM Film WHERE year > 2001 GROUP BY director; Important: Every element in SELECT clause must be a grouping column or an aggregation function. e.g., SELECT director, year, COUNT(*) would not be allowed (in the query above) unless also grouping by year: i.e., GROUP BY director, year 1

48 Filtering Out Whole Groups After partitioning into groups, whole partitions can be discarded i.e., HAVING clause specifies a condition on the grouped tuples SELECT DNO, COUNT(*), AVG(SALARY) FROM EMPLOYEE GROUP BY DNO HAVING COUNT(*) > 2; HAVING clause cannot reference individual tuples within a group Instead, can reference grouping column(s) and aggregates only Contrast WHERE clause to HAVING clause Note: As for aggregation, no GROUP BY clause means relation treated as one group 2

49 Sorting Query Results Show the department names and their locations in alphabetical order SELECT DNAME, DLOCATION FROM DEPARTMENT D, DEPT_LOCATIONS DL WHERE D.DNUMBER = DL.DNUMBER ORDER BY DNAME ASC, DLOCATION DESC; DNAME Administration Headquarters Research Research Research DLOCATION Stafford Houston Sugarland Houston Bellaire 3

50 SQL Data Manipulation

51 Inserting Data INSERT INTO <table> (<attr>, ) VALUES ( <val>, ) ; INSERT INTO <table> (<attr>, ) <subquery> ; Store information about how many hours an employee works for the project 1' into WORKS_ON. INSERT INTO WORKS_ON VALUES ( , 1, 32.); Integrity constraint! Referential integrity constraint!

52 Updating Data UPDATE <table> SET <attr> = <val>, WHERE <condition> ; UPDATE <table> SET (<attr>,.) = ( <subquery> ) WHERE <condition> ; Integrity constraint! Referential integrity constraint! Give all employees in the Research department a 10% raise in salary UPDATE EMPLOYEE SET SALARY = SALARY*1.1 WHERE DNO IN (SELECT DNUMBER FROM DEPARTMENT WHERE DNAME = Research ); 6

53 Deleting Data DELETE FROM <table> WHERE <condition> ; Delete the employees having the last name Borg from the EMPLOYEE table. DELETE FROM EMPLOYEE WHERE LNAME = Borg ; Foreign key EMPLOYEE FNAME M LNAME SSN Ramesh K Narayan Joyce A English Ahmad V Jabbar James E Borg DEPARTMENT DNAME DNUMBER MGRSSN Research Administration Headquarters ON DELETE SET NULL / DEFAULT / CASCADE? Referential integrity constraint! 7

54 Views

55 What are Views? A virtual table derived from other (possibly virtual) tables, i.e. always up-to-date CREATE VIEW dept_view AS SELECT DNO, COUNT(*) AS C, AVG(SALARY) AS S FROM EMPLOYEE GROUP BY DNO; Why? Simplify query commands Provide data security Enhance programming productivity 9

56

Database Technology. Topic 3: SQL. Olaf Hartig.

Database Technology. Topic 3: SQL. Olaf Hartig. Olaf Hartig olaf.hartig@liu.se Structured Query Language Declarative language (what data to get, not how) Considered one of the major reasons for the commercial success of relational databases Statements

More information

Database design process

Database design process Database technology Lecture 2: Relational databases and SQL Jose M. Peña jose.m.pena@liu.se Database design process 1 Relational model concepts... Attributes... EMPLOYEE FNAME M LNAME SSN BDATE ADDRESS

More information

Overview Relational data model

Overview Relational data model Thanks to José and Vaida for most of the slides. Relational databases and MySQL Juha Takkinen juhta@ida.liu.se Outline 1. Introduction: Relational data model and SQL 2. Creating tables in Mysql 3. Simple

More information

Database Technology. Topic 3: SQL. Structured Query Language. Creating Tables SQL DDL. Creating Tables (Example) Modifying Table Definitions

Database Technology. Topic 3: SQL. Structured Query Language. Creating Tables SQL DDL. Creating Tables (Example) Modifying Table Definitions Structured Query Language eclarative language (what data to get, not how) onsidered one of the major reasons for the commercial success of relational databases Statements for data definitions, queries,

More information

Announcement5 SQL5. Create%and%drop%table5. Basic%SFW%query5. Reading%a%table5. TDDD37%% Database%technology% SQL5

Announcement5 SQL5. Create%and%drop%table5. Basic%SFW%query5. Reading%a%table5. TDDD37%% Database%technology% SQL5 Announcement %% Database%technology% SQL Fang%Wei9Kleiner fang.wei9kleiner@liu.se hbp://www.ida.liu.se/~ Course%registration:%system%problems%from%registration% office.%be%patient. Registration%for%the%lab:%possible%without%being%

More information

SQL STRUCTURED QUERY LANGUAGE

SQL STRUCTURED QUERY LANGUAGE STRUCTURED QUERY LANGUAGE SQL Structured Query Language 4.1 Introduction Originally, SQL was called SEQUEL (for Structured English QUery Language) and implemented at IBM Research as the interface for an

More information

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E)

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E) 1 NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE More Complex SQL Retrieval Queries Self-Joins Renaming Attributes and Results Grouping, Aggregation, and Group Filtering

More information

Introduction to SQL. ECE 650 Systems Programming & Engineering Duke University, Spring 2018

Introduction to SQL. ECE 650 Systems Programming & Engineering Duke University, Spring 2018 Introduction to SQL ECE 650 Systems Programming & Engineering Duke University, Spring 2018 SQL Structured Query Language Major reason for commercial success of relational DBs Became a standard for relational

More information

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E)

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E) 1 NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE More Complex SQL Retrieval Queries Self-Joins Renaming Attributes and Results Grouping, Aggregation, and Group Filtering

More information

COSC344 Database Theory and Applications. Lecture 6 SQL Data Manipulation Language (1)

COSC344 Database Theory and Applications. Lecture 6 SQL Data Manipulation Language (1) COSC344 Database Theory and Applications Lecture 6 SQL Data Manipulation Language (1) COSC344 Lecture 56 1 Overview Last Lecture SQL - DDL This Lecture SQL - DML INSERT DELETE (simple) UPDATE (simple)

More information

COSC344 Database Theory and Applications. σ a= c (P) S. Lecture 4 Relational algebra. π A, P X Q. COSC344 Lecture 4 1

COSC344 Database Theory and Applications. σ a= c (P) S. Lecture 4 Relational algebra. π A, P X Q. COSC344 Lecture 4 1 COSC344 Database Theory and Applications σ a= c (P) S π A, C (H) P P X Q Lecture 4 Relational algebra COSC344 Lecture 4 1 Overview Last Lecture Relational Model This Lecture ER to Relational mapping Relational

More information

CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E)

CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1 CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E) 3 LECTURE OUTLINE Constraints in Relational Databases Update Operations 4 SATISFYING INTEGRITY CONSTRAINTS Constraints are restrictions on the

More information

Slides by: Ms. Shree Jaswal

Slides by: Ms. Shree Jaswal Slides by: Ms. Shree Jaswal Overview of SQL, Data Definition Commands, Set operations, aggregate function, null values, Data Manipulation commands, Data Control commands, Views in SQL, Complex Retrieval

More information

CIS611 Lab Assignment 1 SS Chung

CIS611 Lab Assignment 1 SS Chung CIS611 Lab Assignment 1 SS Chung 1. Creating a Relational Database Schema from ER Diagram, Populating the Database and Querying Over the database with SQL 2. Automatic Creation and Maintenance of Database

More information

ECE 650 Systems Programming & Engineering. Spring 2018

ECE 650 Systems Programming & Engineering. Spring 2018 ECE 650 Systems Programming & Engineering Spring 2018 Introduction to SQL Tyler Bletsch Duke University Slides are adapted from Brian Rogers (Duke) Structured Query Language SQL Major reason for commercial

More information

Session Active Databases (2+3 of 3)

Session Active Databases (2+3 of 3) INFO-H-415 - Advanced Databes Session 2+3 - Active Databes (2+3 of 3) Consider the following databe schema: DeptLocation DNumber DLocation Employee FName MInit LName SSN BDate Address Sex Salary SuperSSN

More information

ECE 650 Systems Programming & Engineering. Spring 2018

ECE 650 Systems Programming & Engineering. Spring 2018 ECE 650 Systems Programming & Engineering Spring 2018 Relational Databases: Tuples, Tables, Schemas, Relational Algebra Tyler Bletsch Duke University Slides are adapted from Brian Rogers (Duke) Overview

More information

Part 1 on Table Function

Part 1 on Table Function CIS611 Lab Assignment 1 SS Chung 1. Write Table Functions 2. Automatic Creation and Maintenance of Database from Web Interface 3. Transforming a SQL Query into an Execution Plan in Relational Algebra for

More information

Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries

Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries Copyright 2004 Pearson Education, Inc. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries Copyright 2004 Pearson Education, Inc. 1 Data Definition, Constraints, and Schema Changes Used

More information

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 1 BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL Set Operations in SQL 3 BASIC SQL Structured

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 7 More SQL: Complex Queries, Triggers, Views, and Schema Modification Slide 7-2 Chapter 7 Outline More Complex SQL Retrieval Queries Specifying Semantic Constraints as Assertions and Actions as

More information

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 1 BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 2 CHAPTER 4 OUTLINE SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL Set Operations in SQL 3 BASIC SQL Structured

More information

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530 Translation of ER-diagram into Relational Schema Dr. Sunnie S. Chung CIS430/530 Learning Objectives Define each of the following database terms 9.2 Relation Primary key Foreign key Referential integrity

More information

SQL. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe

SQL. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe SQL Copyright 2013 Ramez Elmasri and Shamkant B. Navathe Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations) of a database Copyright

More information

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1 COSC344 Database Theory and Applications Lecture 5 SQL - Data Definition Language COSC344 Lecture 5 1 Overview Last Lecture Relational algebra This Lecture Relational algebra (continued) SQL - DDL CREATE

More information

Some different database system architectures. (a) Shared nothing architecture.

Some different database system architectures. (a) Shared nothing architecture. Figure.1 Some different database system architectures. (a) Shared nothing architecture. Computer System 1 Computer System CPU DB CPU DB MEMORY MEMORY Switch Computer System n CPU DB MEMORY Figure.1 continued.

More information

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement Chapter 4 Basic SQL Basic SQL SQL language Considered one of the major reasons for the commercial success of relational databases SQL Structured Query Language Statements for data definitions, queries,

More information

Advanced Databases. Winter Term 2012/13. Prof. Dr. Dietmar Seipel University of Würzburg. Advanced Databases Winter Term 2012/13

Advanced Databases. Winter Term 2012/13. Prof. Dr. Dietmar Seipel University of Würzburg. Advanced Databases Winter Term 2012/13 Advanced Databases Winter Term 2012/13 Prof. Dr. Dietmar Seipel University of Würzburg Prof. Dr. Dietmar Seipel Minit FName LName Sex Adress Salary N WORKS_FOR 1 Name Number Locations Name SSN EMPLOYEE

More information

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA Chapter 6: Relational Data Model and Relational Algebra 1 Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA RELATIONAL MODEL CONCEPTS The relational model represents the database as a collection

More information

SQL-99: Schema Definition, Basic Constraints, and Queries. Create, drop, alter Features Added in SQL2 and SQL-99

SQL-99: Schema Definition, Basic Constraints, and Queries. Create, drop, alter Features Added in SQL2 and SQL-99 SQL-99: Schema Definition, Basic Constraints, and Queries Content Data Definition Language Create, drop, alter Features Added in SQL2 and SQL-99 Basic Structure and retrieval queries in SQL Set Operations

More information

Outline. Textbook Chapter 6. Note 1. CSIE30600/CSIEB0290 Database Systems Basic SQL 2

Outline. Textbook Chapter 6. Note 1. CSIE30600/CSIEB0290 Database Systems Basic SQL 2 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features of SQL Textbook Chapter 6 CSIE30600/CSIEB0290

More information

A taxonomy of SQL queries Learning Plan

A taxonomy of SQL queries Learning Plan A taxonomy of SQL queries Learning Plan a. Simple queries: selection, projection, sorting on a simple table i. Small-large number of attributes ii. Distinct output values iii. Renaming attributes iv. Computed

More information

CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E)

CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1 CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E) QUESTION Film title genre year director runtime budget gross The Company Men drama 2010 John Wells 104 15,000,000 4,439,063 Steven Lincoln biography

More information

CSIE30600 Database Systems Basic SQL 2. Outline

CSIE30600 Database Systems Basic SQL 2. Outline Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features of SQL CSIE30600 Database Systems

More information

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530 Translation of ER-diagram into Relational Schema Dr. Sunnie S. Chung CIS430/530 Learning Objectives Define each of the following database terms 9.2 Relation Primary key Foreign key Referential integrity

More information

Relational Algebra Part I. CS 377: Database Systems

Relational Algebra Part I. CS 377: Database Systems Relational Algebra Part I CS 377: Database Systems Recap of Last Week ER Model: Design good conceptual models to store information Relational Model: Table representation with structures and constraints

More information

Chapter 8. Joined Relations. Joined Relations. SQL-99: Schema Definition, Basic Constraints, and Queries

Chapter 8. Joined Relations. Joined Relations. SQL-99: Schema Definition, Basic Constraints, and Queries Copyright 2004 Pearson Education, Inc. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries Joined Relations Can specify a "joined relation" in the FROM-clause Looks like any other relation

More information

More SQL: Complex Queries, Triggers, Views, and Schema Modification

More SQL: Complex Queries, Triggers, Views, and Schema Modification Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries

More information

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra Relational Data Model and Relational Constraints Part 1 A simplified diagram to illustrate the main

More information

CS275 Intro to Databases

CS275 Intro to Databases CS275 Intro to Databases The Relational Data Model Chap. 3 How Is Data Retrieved and Manipulated? Queries Data manipulation language (DML) Retrieval Add Delete Update An Example UNIVERSITY database Information

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 6 Basic SQL Slide 6-2 Chapter 6 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features

More information

More SQL: Complex Queries, Triggers, Views, and Schema Modification

More SQL: Complex Queries, Triggers, Views, and Schema Modification Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries

More information

Data Manipulation Language (DML)

Data Manipulation Language (DML) In the name of Allah Islamic University of Gaza Faculty of Engineering Computer Engineering Department ECOM 4113 DataBase Lab Lab # 3 Data Manipulation Language (DML) El-masry 2013 Objective To be familiar

More information

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation Basic SQL Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation MIDTERM EXAM 2 Basic

More information

The Relational Data Model and Relational Database Constraints

The Relational Data Model and Relational Database Constraints The Relational Data Model and Relational Database Constraints First introduced by Ted Codd from IBM Research in 1970, seminal paper, which introduced the Relational Model of Data representation. It is

More information

Dr. Anis Koubaa. Advanced Databases SE487. Prince Sultan University

Dr. Anis Koubaa. Advanced Databases SE487. Prince Sultan University Advanced Databases Prince Sultan University College of Computer and Information Sciences Fall 2013 Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases Anis Koubaa SE487

More information

Basic SQL II. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

Basic SQL II. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation Basic SQL II Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation Lab 1 Review

More information

Integrity Coded Relational Databases (ICRDB) - Protecting Data Integrity in Clouds

Integrity Coded Relational Databases (ICRDB) - Protecting Data Integrity in Clouds Integrity Coded Relational Databases (ICRDB) - Protecting Data Integrity in Clouds Jyh-haw Yeh Dept. of Computer Science, Boise State University, Boise, Idaho 83725, USA Abstract 1 Introduction Database-as-a-service

More information

RELATIONAL DATA MODEL

RELATIONAL DATA MODEL RELATIONAL DATA MODEL 3.1 Introduction The relational model of data was introduced by Codd (1970). It is based on a simple and uniform data structure - the relation - and has a solid theoretical and mathematical

More information

Data Definition Language (DDL)

Data Definition Language (DDL) Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Database Lab (ECOM 4113) Lab 6 Data Definition Language (DDL) Eng. Mohammed Alokshiya November 11, 2014 Database Keys A key

More information

More SQL: Complex Queries, Triggers, Views, and Schema Modification

More SQL: Complex Queries, Triggers, Views, and Schema Modification Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries

More information

SQL Introduction. CS 377: Database Systems

SQL Introduction. CS 377: Database Systems SQL Introduction CS 377: Database Systems Recap: Last Two Weeks Requirement analysis Conceptual design Logical design Physical dependence Requirement specification Conceptual data model (ER Model) Representation

More information

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries

More information

PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II

PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore 560100 ) Solution Set - Test-II Sub: Database Management Systems 16MCA23 Date: 04/04/2017 Sem & Section:II Duration:

More information

COSC Assignment 2

COSC Assignment 2 COSC 344 Overview In this assignment, you will turn your miniworld into a set of Oracle tables, normalize your design, and populate your database. Due date for assignment 2 Friday, 25 August 2017 at 4

More information

SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT

SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT Contents 1 The COMPANY Database 2 SQL developments: an overview 3 DDL: Create, Alter, Drop 4 DML: select, insert, update, delete 5 Triggers The

More information

THE RELATIONAL DATA MODEL CHAPTER 3 (6/E) CHAPTER 5 (5/E)

THE RELATIONAL DATA MODEL CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1 THE RELATIONAL DATA MODEL CHAPTER 3 (6/E) CHAPTER 5 (5/E) 2 LECTURE OUTLINE Relational Model Concepts Relational Database Schemas Update Operations Brief History of Database Applications (from Section

More information

Relational Model. CS 377: Database Systems

Relational Model. CS 377: Database Systems Relational Model CS 377: Database Systems ER Model: Recap Recap: Conceptual Models A high-level description of the database Sufficiently precise that technical people can understand it But, not so precise

More information

Query 2: Pnumber Dnum Lname Address Bdate 10 4 Wallace 291 Berry, Bellaire, TX Wallace 291 Berry, Bellaire, TX

Query 2: Pnumber Dnum Lname Address Bdate 10 4 Wallace 291 Berry, Bellaire, TX Wallace 291 Berry, Bellaire, TX 5.11 No violation, integrity is retained. Dnum = 2 does not exist. This can be solved by adding a foreign key referencing the department table, so the operation does not execute. Dnum = 4 already exists,

More information

SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT

SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT Contents 1 The COMPANY Database 2 SQL developments: an overview 3 DDL: Create, Alter, Drop 4 DML: select, insert, update, delete 5 Triggers The

More information

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Chapter 5 Outline More Complex SQL Retrieval

More information

Basic SQL. Basic SQL. Basic SQL

Basic SQL. Basic SQL. Basic SQL Basic SQL Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation Basic SQL Structured

More information

Chapter 8: Relational Algebra

Chapter 8: Relational Algebra Chapter 8: elational Algebra Outline: Introduction Unary elational Operations. Select Operator (σ) Project Operator (π) ename Operator (ρ) Assignment Operator ( ) Binary elational Operations. Set Operators

More information

Structured Query Language (SQL)

Structured Query Language (SQL) Structured Query Language (SQL) SQL Chapters 6 & 7 (7 th edition) Chapters 4 & 5 (6 th edition) PostgreSQL on acsmysql1.acs.uwinnipeg.ca Each student has a userid and initial password acs!

More information

Relational Algebra & Calculus. CS 377: Database Systems

Relational Algebra & Calculus. CS 377: Database Systems Relational Algebra & Calculus CS 377: Database Systems Quiz #1 Question: What is metadata and why is it important? Answer: Metadata is information about the data such as name, type, size. It is important

More information

Relational Database Systems Part 01. Karine Reis Ferreira

Relational Database Systems Part 01. Karine Reis Ferreira Relational Database Systems Part 01 Karine Reis Ferreira karine@dpi.inpe.br Aula da disciplina Computação Aplicada I (CAP 241) 2016 Database System Database: is a collection of related data. represents

More information

Chapter 5 Relational Algebra. Nguyen Thi Ai Thao

Chapter 5 Relational Algebra. Nguyen Thi Ai Thao Chapter 5 Nguyen Thi Ai Thao thaonguyen@cse.hcmut.edu.vn Spring- 2016 Contents 1 Unary Relational Operations 2 Operations from Set Theory 3 Binary Relational Operations 4 Additional Relational Operations

More information

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION JING YANG 2010 FALL Class 3: The Relational Data Model and Relational Database Constraints Outline 2 The Relational Data Model and Relational Database Constraints

More information

L130 - DATABASE MANAGEMENT SYSTEMS LAB CYCLE-1 1) Create a table STUDENT with appropriate data types and perform the following queries.

L130 - DATABASE MANAGEMENT SYSTEMS LAB CYCLE-1 1) Create a table STUDENT with appropriate data types and perform the following queries. L130 - DATABASE MANAGEMENT SYSTEMS LAB CYCLE-1 1) Create a table STUDENT with appropriate data types and perform the following queries. Roll number, student name, date of birth, branch and year of study.

More information

Chapter 8: The Relational Algebra and The Relational Calculus

Chapter 8: The Relational Algebra and The Relational Calculus Ramez Elmasri, Shamkant B. Navathe(2017) Fundamentals of Database Systems (7th Edition),pearson, isbn 10: 0-13-397077-9;isbn-13:978-0-13-397077-7. Chapter 8: The Relational Algebra and The Relational Calculus

More information

In Chapters 3 through 6, we presented various aspects

In Chapters 3 through 6, we presented various aspects 15 chapter Basics of Functional Dependencies and Normalization for Relational Databases In Chapters 3 through 6, we presented various aspects of the relational model and the languages associated with it.

More information

Chapter 6 The Relational Algebra and Calculus

Chapter 6 The Relational Algebra and Calculus Chapter 6 The Relational Algebra and Calculus 1 Chapter Outline Example Database Application (COMPANY) Relational Algebra Unary Relational Operations Relational Algebra Operations From Set Theory Binary

More information

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 304 Introduction to Database Systems SQL DDL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Overview Structured Query Language or SQL is the standard query language

More information

The Basic (Flat) Relational Model. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

The Basic (Flat) Relational Model. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Basic (Flat) Relational Model Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 Outline The Relational Data Model and Relational Database Constraints Relational

More information

Course Notes on Relational Algebra

Course Notes on Relational Algebra Course Notes on Relational Algebra What is the Relational Algebra? Relational Algebra: Summary Operators Selection Projection Union, Intersection, Difference Cartesian Product Join Division Equivalences

More information

The Relational Model and Relational Algebra

The Relational Model and Relational Algebra The Relational Model and Relational Algebra Background Introduced by Ted Codd of IBM Research in 1970. Concept of mathematical relation as the underlying basis. The standard database model for most transactional

More information

DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E)

DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1 DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE Updating Databases Using SQL Specifying Constraints as Assertions and Actions as Triggers Schema Change Statements in

More information

Key Points. COSC 122 Computer Fluency. Databases. What is a database? Databases in the Real-World DBMS. Database System Approach

Key Points. COSC 122 Computer Fluency. Databases. What is a database? Databases in the Real-World DBMS. Database System Approach COSC 122 Computer Fluency Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) allow for easy storage and retrieval of large amounts of information. 2) Relational

More information

Relational Algebra 1

Relational Algebra 1 Relational Algebra 1 Motivation The relational data model provides a means of defining the database structure and constraints NAME SALARY ADDRESS DEPT Smith 50k St. Lucia Printing Dilbert 40k Taringa Printing

More information

COSC 304 Introduction to Database Systems SQL. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 304 Introduction to Database Systems SQL. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 304 Introduction to Database Systems SQL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Queries Querying with SQL is performed using a SELECT statement. The general

More information

Relational Calculus: 1

Relational Calculus: 1 CSC 742 Database Management Systems Topic #8: Relational Calculus Spring 2002 CSC 742: DBMS by Dr. Peng Ning 1 Relational Calculus: 1 Can define the information to be retrieved not any specific series

More information

SQL: Advanced Queries, Assertions, Triggers, and Views. Copyright 2012 Ramez Elmasri and Shamkant B. Navathe

SQL: Advanced Queries, Assertions, Triggers, and Views. Copyright 2012 Ramez Elmasri and Shamkant B. Navathe SQL: Advanced Queries, Assertions, Triggers, and Views Copyright 2012 Ramez Elmasri and Shamkant B. Navathe NULLS IN SQL QUERIES SQL allows queries that check if a value is NULL (missing or undefined or

More information

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables INDEX Exercise No Title 1 Basic SQL Statements 2 Restricting and Sorting Data 3 Single Row Functions 4 Displaying data from multiple tables 5 Creating and Managing Tables 6 Including Constraints 7 Manipulating

More information

The Relational Algebra and Calculus. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe

The Relational Algebra and Calculus. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe The Relational Algebra and Calculus Copyright 2013 Ramez Elmasri and Shamkant B. Navathe Chapter Outline Relational Algebra Unary Relational Operations Relational Algebra Operations From Set Theory Binary

More information

CS 338 Basic SQL Part II

CS 338 Basic SQL Part II CS 338 Basic SQL Part II Bojana Bislimovska Spring 2017 Major research Outline Basic Retrieval Queries Exercises Ambiguous Attribute Names Major research Same name can be used for two or more attributes

More information

Algorithms for Query Processing and Optimization. 0. Introduction to Query Processing (1)

Algorithms for Query Processing and Optimization. 0. Introduction to Query Processing (1) Chapter 19 Algorithms for Query Processing and Optimization 0. Introduction to Query Processing (1) Query optimization: The process of choosing a suitable execution strategy for processing a query. Two

More information

SQL: A COMMERCIAL DATABASE LANGUAGE. Data Change Statements,

SQL: A COMMERCIAL DATABASE LANGUAGE. Data Change Statements, SQL: A COMMERCIAL DATABASE LANGUAGE Data Change Statements, Outline 1. Introduction 2. Data Definition, Basic Constraints, and Schema Changes 3. Basic Queries 4. More complex Queries 5. Aggregate Functions

More information

DATABASE CONCEPTS. Dr. Awad Khalil Computer Science & Engineering Department AUC

DATABASE CONCEPTS. Dr. Awad Khalil Computer Science & Engineering Department AUC DATABASE CONCEPTS Dr. Awad Khalil Computer Science & Engineering Department AUC s are considered as major components in almost all recent computer application systems, including business, management, engineering,

More information

SQL Queries. COSC 304 Introduction to Database Systems SQL. Example Relations. SQL and Relational Algebra. Example Relation Instances

SQL Queries. COSC 304 Introduction to Database Systems SQL. Example Relations. SQL and Relational Algebra. Example Relation Instances COSC 304 Introduction to Database Systems SQL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Queries Querying with SQL is performed using a SELECT statement. The general

More information

Chapter 6 5/2/2008. Chapter Outline. Database State for COMPANY. The Relational Algebra and Calculus

Chapter 6 5/2/2008. Chapter Outline. Database State for COMPANY. The Relational Algebra and Calculus Chapter 6 The Relational Algebra and Calculus Chapter Outline Example Database Application (COMPANY) Relational Algebra Unary Relational Operations Relational Algebra Operations From Set Theory Binary

More information

Ref1 for STUDENT RECORD DB: Ref2 for COMPANY DB:

Ref1 for STUDENT RECORD DB: Ref2 for COMPANY DB: Lect#5: SQL Ref1 for STUDENT RECORD DB: Database Design and Implementation Edward Sciore, Boston College ISBN: 978-0-471-75716-0 Ref2 for COMPANY DB: Fund. of Database Systems, Elmasri, Navathe, 5th ed.,

More information

Guides for Installing MS SQL Server and Creating Your First Database. Please see more guidelines on installing procedure on the class webpage

Guides for Installing MS SQL Server and Creating Your First Database. Please see more guidelines on installing procedure on the class webpage Guides for Installing MS SQL Server and Creating Your First Database Installing process Please see more guidelines on installing procedure on the class webpage 1. Make sure that you install a server with

More information

Chapter 3. Algorithms for Query Processing and Optimization

Chapter 3. Algorithms for Query Processing and Optimization Chapter 3 Algorithms for Query Processing and Optimization Chapter Outline 1. Introduction to Query Processing 2. Translating SQL Queries into Relational Algebra 3. Algorithms for External Sorting 4. Algorithms

More information

Relational Algebra. Relational Algebra Overview. Relational Algebra Overview. Unary Relational Operations 8/19/2014. Relational Algebra Overview

Relational Algebra. Relational Algebra Overview. Relational Algebra Overview. Unary Relational Operations 8/19/2014. Relational Algebra Overview The Relational Algebra Relational Algebra Relational algebra is the basic set of operations for the relational model These operations enable a user to specify basic retrieval requests (or queries) Relational

More information

The Relational Data Model and Relational Database Constraints

The Relational Data Model and Relational Database Constraints CHAPTER 5 The Relational Data Model and Relational Database Constraints Copyright 2017 Ramez Elmasri and Shamkant B. Navathe Slide 1-2 Chapter Outline Relational Model Concepts Relational Model Constraints

More information

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity COSC 416 NoSQL Databases Relational Model (Review) Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Relational Model History The relational model was proposed by E. F. Codd

More information

Introduction to Query Processing and Query Optimization Techniques. Copyright 2011 Ramez Elmasri and Shamkant Navathe

Introduction to Query Processing and Query Optimization Techniques. Copyright 2011 Ramez Elmasri and Shamkant Navathe Introduction to Query Processing and Query Optimization Techniques Outline Translating SQL Queries into Relational Algebra Algorithms for External Sorting Algorithms for SELECT and JOIN Operations Algorithms

More information

RELATIONAL DATA MODEL: Relational Algebra

RELATIONAL DATA MODEL: Relational Algebra RELATIONAL DATA MODEL: Relational Algebra Outline 1. Relational Algebra 2. Relational Algebra Example Queries 1. Relational Algebra A basic set of relational model operations constitute the relational

More information

CSEN 501 CSEN501 - Databases I

CSEN 501 CSEN501 - Databases I CSEN501 - Databases I Lecture 5: Structured Query Language (SQL) Prof. Dr. Slim slim.abdennadher@guc.edu.eg German University Cairo, Faculty of Media Engineering and Technology Structured Query Language:

More information

CS 348 Introduction to Database Management Assignment 2

CS 348 Introduction to Database Management Assignment 2 CS 348 Introduction to Database Management Assignment 2 Due: 30 October 2012 9:00AM Returned: 8 November 2012 Appeal deadline: One week after return Lead TA: Jiewen Wu Submission Instructions: By the indicated

More information