Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 480: Database Systems Lecture 8 February 1, 2013.

Similar presentations


Presentation on theme: "CS 480: Database Systems Lecture 8 February 1, 2013."— Presentation transcript:

1 CS 480: Database Systems Lecture 8 February 1, 2013

2 Division () Let r(R) and s(S) be relations such that S  R.
Then r  s consists of every tuple t in ΠR–S(r) that satisfies the following condition: If every tuple in s is appended to t, then the resulting tuple is in r. The result is defined over the scheme R-S.

3 Division () Numerator: Denominator: Supplier-id Part-id 1 2 3 4 5 6
Result: Supplier-id 1 4

4 Division () What are the student-id’s of students who took both 480 and 580, and got an A in both? Enrollment: s: Student-id Course# Grade 23 480 A 580 25 230 B+ 250 C 28 Course# Grade 480 A 580 Enrollment  s Student-id 23 28

5 Division () What are the student-id’s of students who took both 480 and 580, and got an A in both? Enrollment: What’s an alternative algebra expression that would answer this query? Student-id Course# Grade 23 480 A 580 25 230 B+ 250 C 28 Select students with A in 480 Select students with A in 580 Project their student-id’s Compute Intersection

6 Examples #1 Relational Schema
order(order#,retailer-name,item,quantity) supplier(supp#,supp-name,item,price)

7 Examples #1 Relational Schema Query
order(order#,retailer-name,item,quantity) supplier(supp#,supp-name,item,price) Query Retrieve the name of suppliers that supply every item that was endorsed by ‘Jewel’

8 Examples #1 Relational Schema Query
order(order#,retailer-name,item,quantity) supplier(supp#,supp-name,item,price) Query Retrieve the name of suppliers that supply every item that was endorsed by ‘Jewel’ Gives us a clue that we want to do a division.

9 Examples #1 Relational Schema Query
order(order#,retailer-name,item,quantity) supplier(supp#,supp-name,item,price) Query Retrieve the name of suppliers that supply every item that was endorsed by ‘Jewel’ Think of the target. We want just the supp-name. Also they have in common the ITEM and that’s what should be repeated Gives us a clue that we want to do a division. What’s the numerator and what’s the denominator?

10 Examples #1 Relational Schema Query Relational Algebra Query
order(order#,retailer-name,item,quantity) supplier(supp#,supp-name,item,price) Query Retrieve the name of suppliers that supply every item that was endorsed by ‘Jewel’ Relational Algebra Query Πsupp-name,item(X)  Πitem(Y) WHAT IS Y? Y should be “every item that was ordered by Jewel” WHAT IS X? We want to get the suppliers so then we should put it as X.

11 Examples #1 Relational Schema Query Relational Algebra Query
order(order#,retailer-name,item,quantity) supplier(supp#,supp-name,item,price) Query Retrieve the name of suppliers that supply every item that was endorsed by ‘Jewel’ Relational Algebra Query Πsupp-name,item(supplier)  Πitem(σretailer-name=‘Jewel’(order))

12 Examples #2 Relational Schema Part(part-id, part-name, color)
Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity)

13 Examples #2, Query #1 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #1: Retrieve the names of suppliers that have shipments of part #2. Steps to take?

14 Examples #2, Query #1 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #1: Retrieve the names of suppliers that have shipments of part #2. Steps to take? Select the shipments of part #2.

15 Examples #2, Query #1 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #1: Retrieve the names of suppliers that have shipments of part #2. Steps to take? Select the shipments of part #2. Link these shipments with the supplier information (to get the supplier names).

16 Examples #2, Query #1 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #1: Retrieve the names of suppliers that have shipments of part #2. Steps to take? Select the shipments of part #2. Link these shipments with the supplier information (to get the supplier names). Extract the supplier names.

17 Examples #2, Query #1 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #1: Retrieve the names of suppliers that have shipments of part #2. Step 1: Select the shipments of Part #2.

18 Examples #2, Query #1 Πsupp-name(σpart-id=‘2’(supplies) supplier)
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #1: Retrieve the names of suppliers that have shipments of part #2. Step 1: Select the shipments of Part #2. Πsupp-name(σpart-id=‘2’(supplies) supplier)

19 Examples #2, Query #1 Πsupp-name(σpart-id=‘2’(supplies) supplier)
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #1: Retrieve the names of suppliers that have shipments of part #2. Step 2: Link these shipments with the supplier information (to get the supplier names). Πsupp-name(σpart-id=‘2’(supplies) supplier)

20 Examples #2, Query #1 Πsupp-name(σpart-id=‘2’(supplies) supplier
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #1: Retrieve the names of suppliers that have shipments of part #2. Step 2: Link these shipments with the supplier information (to get the supplier names). Πsupp-name(σpart-id=‘2’(supplies) supplier

21 Examples #2, Query #1 Πsupp-name(σpart-id=‘2’(supplies) supplier)
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #1: Retrieve the names of suppliers that have shipments of part #2. Step 3: Extract the supplier names. Πsupp-name(σpart-id=‘2’(supplies) supplier)

22 Examples #2, Query #1 Πsupp-name(σpart-id=‘2’(supplies) supplier)
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #1: Retrieve the names of suppliers that have shipments of part #2. Step 3: Extract the supplier names. Πsupp-name(σpart-id=‘2’(supplies) supplier)

23 Examples #2, Query #1 Πsupp-name(σpart-id=‘2’(supplies) supplier)
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #1: Retrieve the names of suppliers that have shipments of part #2. Πsupp-name(σpart-id=‘2’(supplies) supplier)

24 Examples #2, Query #2 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers.

25 Examples #2, Query #2 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers.

26 Examples #2, Query #2 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers.

27 Examples #2, Query #2 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers.

28 Examples #2, Query #2 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers.

29 Examples #2, Query #2 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers.

30 Examples #2, Query #2 Πsupp-name(supplier
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers. Step 1: Extract all parts that are red. Πsupp-name(supplier Πsupp-id(Πpart-id(σcolor=‘red’(parts)) supplies)))

31 Examples #2, Query #2 Πsupp-name(supplier
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers. Step 1: Extract all parts that are red. Πsupp-name(supplier Πsupp-id(Πpart-id(σcolor=‘red’(parts)) supplies)))

32 Examples #2, Query #2 Πsupp-name(supplier
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers. Step 2: Get the part numbers for those red parts. Πsupp-name(supplier Πsupp-id(Πpart-id(σcolor=‘red’(parts)) supplies)))

33 Examples #2, Query #2 Πsupp-name(supplier
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers. Step 2: Get the part numbers for those red parts. Πsupp-name(supplier Πsupp-id(Πpart-id(σcolor=‘red’(parts)) supplies)))

34 Examples #2, Query #2 Πsupp-name(supplier
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers. Step 3: Extract all shipments of those red parts. Πsupp-name(supplier Πsupp-id(Πpart-id(σcolor=‘red’(parts)) supplies)))

35 Examples #2, Query #2 Πsupp-name(supplier
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers. Step 3: Extract all shipments of those red parts. Πsupp-name(supplier Πsupp-id(Πpart-id(σcolor=‘red’(parts)) supplies)))

36 Examples #2, Query #2 Πsupp-name(supplier
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers. Step 4: Get the suppliers of those shipments. Πsupp-name(supplier Πsupp-id(Πpart-id(σcolor=‘red’(parts)) supplies)))

37 Examples #2, Query #2 Πsupp-name(supplier
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers. Step 4: Get the suppliers of those shipments. Πsupp-name(supplier Πsupp-id(Πpart-id(σcolor=‘red’(parts)) supplies)))

38 Examples #2, Query #2 Πsupp-name(supplier
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers. Step 5: Get the supplier names of those suppliers. Projection of supp-id may not be needed. Πsupp-name(supplier Πsupp-id(Πpart-id(σcolor=‘red’(parts)) supplies))

39 Examples #2, Query #2 Πsupp-name(supplier
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #2: Retrieve the names of suppliers that have shipments of at least one ‘red’ part. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers. Πsupp-name(supplier Πsupp-id(Πpart-id(σcolor=‘red’(parts)) supplies))

40 Examples #2, Query #3 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #3: Give the names of suppliers that have shipments of all the parts. Steps to take? Extract all parts that are red. Get the part numbers for those red parts. Extract all shipments of those red parts. Get the suppliers of those shipments. Get the supplier names of those suppliers.

41 Examples #2, Query #3 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #3: Give the names of suppliers that have shipments of all the parts. Steps to take? Division between the shipments and all the part-id’s (this will give us supplier-id’s of such suppliers). Get the part numbers for those red parts. Get the suppliers of those shipments.

42 Examples #2, Query #3 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #3: Give the names of suppliers that have shipments of all the parts. Steps to take? Division between the shipments and all the part-id’s (this will give us supplier-id’s of such suppliers). Use those supplier-id’s to get their names. Get the suppliers of those shipments.

43 Examples #2, Query #3 Πsupp-name((Πsupp-id,part-id(supplies) 
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #3: Give the names of suppliers that have shipments of all the parts. Steps to take? Division between the shipments and all the part-id’s (this will give us supplier-id’s of such suppliers). Use those supplier-id’s to get their names. Get the suppliers of those shipments. Step 1: Division between the shipments and all the part-id’s (this will give us supplier-id’s of such suppliers). Πsupp-name((Πsupp-id,part-id(supplies)  Πpart-id(part)) supplier)

44 Examples #2, Query #3 Πsupp-name((Πsupp-id,part-id(supplies) 
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #3: Give the names of suppliers that have shipments of all the parts. Steps to take? Division between the shipments and all the part-id’s (this will give us supplier-id’s of such suppliers). Use those supplier-id’s to get their names. Get the suppliers of those shipments. Step 1: Division between the shipments and all the part-id’s (this will give us supplier-id’s of such suppliers). Πsupp-name((Πsupp-id,part-id(supplies)  Πpart-id(part)) supplier)

45 Examples #2, Query #3 Πsupp-name((Πsupp-id,part-id(supplies) 
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #3: Give the names of suppliers that have shipments of all the parts. Steps to take? Division between the shipments and all the part-id’s (this will give us supplier-id’s of such suppliers). Use those supplier-id’s to get their names. Get the suppliers of those shipments. Step 2: Use those supplier-id’s to get their names. Πsupp-name((Πsupp-id,part-id(supplies)  Πpart-id(part)) supplier)

46 Examples #2, Query #3 Πsupp-name((Πsupp-id,part-id(supplies) 
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #3: Give the names of suppliers that have shipments of all the parts. Steps to take? Division between the shipments and all the part-id’s (this will give us supplier-id’s of such suppliers). Use those supplier-id’s to get their names. Get the suppliers of those shipments. Step 2: Use those supplier-id’s to get their names. Πsupp-name((Πsupp-id,part-id(supplies)  Πpart-id(part)) supplier)

47 Examples #2, Query #3 Πsupp-name((Πsupp-id,part-id(supplies) 
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #3: Give the names of suppliers that have shipments of all the parts. Steps to take? Division between the shipments and all the part-id’s (this will give us supplier-id’s of such suppliers). Use those supplier-id’s to get their names. Get the suppliers of those shipments. Step 2: Use those supplier-id’s to get their names. Πsupp-name((Πsupp-id,part-id(supplies)  Πpart-id(part)) supplier)

48 Examples #2, Query #3 Πsupp-name((Πsupp-id,part-id(supplies) 
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #3: Give the names of suppliers that have shipments of all the parts. Steps to take? Division between the shipments and all the part-id’s (this will give us supplier-id’s of such suppliers). Use those supplier-id’s to get their names. Get the suppliers of those shipments. Πsupp-name((Πsupp-id,part-id(supplies)  Πpart-id(part)) supplier)

49 Examples #2, Query #4 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments.

50 Examples #2, Query #4 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments.

51 Examples #2, Query #4 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments.

52 Examples #2, Query #4 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments.

53 Examples #2, Query #4 Relational Schema
Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments. Step 1: Extract all suppliers that do ship part #2.

54 Examples #2, Query #4 Πsupp-name(supplier (Πsupp-id(supplies) –
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments. Step 1: Extract all suppliers that do ship part #2. Πsupp-name(supplier (Πsupp-id(supplies) – Πsupp-id(σpart-id=‘2’(supplies))))

55 Examples #2, Query #4 Πsupp-name(supplier (Πsupp-id(supplies) –
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments. Step 1: Extract all suppliers that do ship part #2. Πsupp-name(supplier (Πsupp-id(supplies) – Πsupp-id(σpart-id=‘2’(supplies))))

56 Examples #2, Query #4 Πsupp-name(supplier (Πsupp-id(supplies) –
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments. Step 2: Using those, compute the ones that do not ship part #2. Πsupp-name(supplier (Πsupp-id(supplies) – Πsupp-id(σpart-id=‘2’(supplies))))

57 Examples #2, Query #4 Πsupp-name(supplier (Πsupp-id(supplier) –
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments. Step 2: Using those, compute the ones that do not ship part #2. Recall that the schemes have to be the same. That’s why we project only the supp-id’s. Πsupp-name(supplier (Πsupp-id(supplier) – Πsupp-id(σpart-id=‘2’(supplies))))

58 Examples #2, Query #4 Πsupp-name(supplier (Πsupp-id(supplier) –
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments. Step 3: From those suppliers, get their names. Recall that the schemes have to be the same. That’s why we project only the supp-id’s. Πsupp-name(supplier (Πsupp-id(supplier) – Πsupp-id(σpart-id=‘2’(supplies))))

59 Examples #2, Query #4 Πsupp-name(supplier (Πsupp-id(supplier) –
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments. Step 3: From those suppliers, get their names. Recall that the schemes have to be the same. That’s why we project only the supp-id’s. Πsupp-name(supplier (Πsupp-id(supplier) – Πsupp-id(σpart-id=‘2’(supplies)))))

60 Examples #2, Query #4 Πsupp-name(supplier (Πsupp-id(supplier) –
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments. Step 3: From those suppliers, get their names. Πsupp-name(supplier (Πsupp-id(supplier) – Πsupp-id(σpart-id=‘2’(supplies))))

61 Examples #2, Query #4 Πsupp-name(supplier (Πsupp-id(supplier) –
Relational Schema Part(part-id, part-name, color) Supplier(supp-id,supp-name,address) Supplies(supp-id,part-id,quantity) Query #4: Names of suppliers that do not have shipments of part #2. Steps to take? Extract all suppliers that do ship part #2. Using those, compute the ones that do not ship part #2. From those suppliers, get their names. Get the suppliers of those shipments. Πsupp-name(supplier (Πsupp-id(supplier) – Πsupp-id(σpart-id=‘2’(supplies))))

62 Examples #3 d-name d-city ba-name ba-city Frequents Drinker Bar Likes
Serves All of them are many to many. Beer be-name type

63 Examples #3 d-name d-city ba-name ba-city Frequents Drinker Bar Likes
Serves Relational Schema: Drinker(d-name,d-city) Bar(ba-name,ba-city) Beer(be-name,type) One relation for each entity set Beer be-name type

64 Examples #3 d-name d-city ba-name ba-city Frequents Drinker Bar Likes
Serves Relational Schema: Drinker(d-name,d-city) Bar(ba-name,ba-city) Beer(be-name,type) Frequents(d-name,ba-name) Serves(ba-name,be-name) Likes(d-name,be-name) One relation for each relationship set Beer be-name type

65 Example #3, Query #1 Relational Schema: DRINKER(d-name,d-city)
BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes?


Download ppt "CS 480: Database Systems Lecture 8 February 1, 2013."

Similar presentations


Ads by Google