Presentation is loading. Please wait.

Presentation is loading. Please wait.

Foundations of Relational Implementation (2) IS 240 – Database Management Lecture #14 – 2004-04-06 Prof. M. E. Kabay, PhD, CISSP Norwich University

Similar presentations


Presentation on theme: "Foundations of Relational Implementation (2) IS 240 – Database Management Lecture #14 – 2004-04-06 Prof. M. E. Kabay, PhD, CISSP Norwich University"— Presentation transcript:

1 Foundations of Relational Implementation (2) IS 240 – Database Management Lecture #14 – Prof. M. E. Kabay, PhD, CISSP Norwich University

2 2 Copyright © 2004 M. E. Kabay. All rights reserved. Topics Today we will work on relational algebra Applying operators to relations Expressing queries as relational algebra

3 The Relations

4 4 Copyright © 2004 M. E. Kabay. All rights reserved. The Operators Union ( + or ) Difference ( - ) Intersection ( ) [Cartesian] Product ( X ) Projection ( Relation[attributes] ) Selection ( WHERE ) JOIN [ Relation1 JOIN (condition) Relation2]

5 5 Copyright © 2004 M. E. Kabay. All rights reserved. Union ( + or ) Combine rows from one table to those of another to form a third, combined table Discard duplicates Tables (relations) must be union-compatible Structure must be the same Same number of fields (attributes) Same domain for each corresponding field

6 6 Copyright © 2004 M. E. Kabay. All rights reserved. Union ( + or ) REFER TO SLIDE 3 FOR THE RELATIONS Which relations are union-compatible? Why? What normal English question does the union of these relations answer? Write out the tuples of A+B or A B where A and B are the relations that are union- compatible.

7 7 Copyright © 2004 M. E. Kabay. All rights reserved. Difference ( - ) Locate the rows that are in the first table that are NOT in the second table Create a table based on those remaining records Difference, unlike union, is not transitive I.e., the order of the operands matters Thus X – Y is not necessarily the same as Y - X

8 8 Copyright © 2004 M. E. Kabay. All rights reserved A B

9 9 Copyright © 2004 M. E. Kabay. All rights reserved. Difference ( - ) What is WaterburyState – CentralVermont? What does this difference mean in English? What is CentralVermont – WaterburyState? What does this difference mean in English?

10 10 Copyright © 2004 M. E. Kabay. All rights reserved. Intersection ( ) Find the rows in the tables that occur in both Put those in a third (new) table

11 11 Copyright © 2004 M. E. Kabay. All rights reserved. Intersection ( ) What is WaterburyState CentralVermont? What does this intersection mean in English?

12 12 Copyright © 2004 M. E. Kabay. All rights reserved. [Cartesian] Product ( X ) Concatenate* (join) each row from one table with every row of the second table May produce nonsensical rows Usually have to extract meaningful data with other operators * Etymology from Latin: Con = with Catena = chain

13 13 Copyright © 2004 M. E. Kabay. All rights reserved. [Cartesian] Product ( X ) Does the Cartesian product of two relations necessarily make sense by itself? What is Doctor X WaterburyState?

14 14 Copyright © 2004 M. E. Kabay. All rights reserved. Projection (Relation[attributes]) Extract certain columns from the rows in a table Thus result is table with fewer columns (attributes) Remove duplicate records that may result

15 15 Copyright © 2004 M. E. Kabay. All rights reserved. Projection ( Relation[attributes] ) What is the projection Patient[LastName,Birthday]? Express this projection as a question. What is the projection PatientDoctor[Patient,Hospital,Bed]? Express this projection as a question.

16 16 Copyright © 2004 M. E. Kabay. All rights reserved. Selection ( WHERE ) Choose certain rows from a table according to specific conditions Put the qualifying rows in a new table

17 17 Copyright © 2004 M. E. Kabay. All rights reserved. Selection ( WHERE ) What is PatientDoctor WHERE Hospital = CentralVermont? Express this selection as a question in English. What is Patient WHERE Birthday < ? Express this selection as a question in English.

18 18 Copyright © 2004 M. E. Kabay. All rights reserved. JOIN [Relation1 JOIN (condition) Relation2] Complex operation involving product, selection and projection 1 st : create product table 2 nd : select appropriate rows from that table 3 rd : choose particular columns needed Equijoin may include columns that have the same meaning Natural join removes duplicate columns

19 19 Copyright © 2004 M. E. Kabay. All rights reserved. JOIN [ Relation1 JOIN (condition) Relation2] What is PatientDoctor JOIN (MedicalStaff = Doctor) Doctor? Use a natural join. What kinds of questions could you answer by such a Join operation?

20 20 Copyright © 2004 M. E. Kabay. All rights reserved. Homework Complete your study of Chapter 8 using Read-Recite-Review phases of SQ3R For Thursday 8 April 2004, use the Survey- Question phases of SQ3R in Chapter 9 on SQL REQUIRED: For Tuesday 13 April 2004, complete written answers to questions for 34 points

21 21 Copyright © 2004 M. E. Kabay. All rights reserved. DISCUSSION


Download ppt "Foundations of Relational Implementation (2) IS 240 – Database Management Lecture #14 – 2004-04-06 Prof. M. E. Kabay, PhD, CISSP Norwich University"

Similar presentations


Ads by Google