Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra) Query Formulation Exercise.

Similar presentations


Presentation on theme: "1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra) Query Formulation Exercise."— Presentation transcript:

1 1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra) Query Formulation Exercise

2 2 Exercises Given relational schema: Sailors (sid, sname, rating, age) Reservation (sid, bid, date) Boats (bid, bname, color) 1) Find names of sailors who’ve reserved boat #103 2) Find names of sailors who’ve reserved a red boat 3) Find sailors who’ve reserved a red or a green boat 4) Find sailors who’ve reserved a red and a green boat 5) Find the names of sailors who’ve reserved all boats

3 3 1) Find names of sailors who’ve reserved boat #103  Solution 1:  Solution 2 :  Solution 3 :

4 4 2) Find names of sailors who’ve reserved a red boat  Boats (bid, bname, color)  Information about boat color only available in Boats; so need an extra join:  A more efficient solution -- why more efficient? A query optimizer can find this, given the first solution!

5 5 3) Find sailors who’ve reserved a red or a green boat  Can identify all red or green boats, then find sailors who’ve reserved one of these boats:  Can also define Tempboats using union! (How?)  What happens if is replaced by in this query?

6 6 4) Find sailors who’ve reserved a red and a green boat  Previous approach won’t work! Why?  Must identify sailors who’ve reserved red boats, sailors who’ve reserved green boats, then find the intersection (note that sid is a key for Sailors):

7 7 4) Find sailors who’ve reserved a red and a green boat  Previous approach won’t work! Why?  Must identify sailors who’ve reserved red boats, sailors who’ve reserved green boats, then find the intersection (note that sid is a key for Sailors):

8 8 5) Find the names of sailors who’ve reserved all boats  Uses division; schemas of the input relations to division (/) must be carefully chosen:  To find sailors who’ve reserved all ‘Interlake’ boats:.....


Download ppt "1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra) Query Formulation Exercise."

Similar presentations


Ads by Google