Download presentation
Presentation is loading. Please wait.
Published byAnthony Cotterill Modified over 9 years ago
1
DB Review Session
2
ER Diagrams 1 Where does the salary attribute belong? Actor id name address birthday Acted In Movie title type year salary
3
id name Actor Acted In Movie The entities in a relationship set identify the relationship How would we store information about a person who acted in one movie in several roles? role title Role title ER Diagrams 2
4
id name Actor Acted In Movie The entities in a relationship set identify the relationship role title ER Diagrams 2
5
id name Actor Acted In Movie The entities in a relationship set identify the relationship How would we store information about a person who acted in one movie in several roles? title Role title ER Diagrams 2
6
ER Diagrams 3 Person id name age FatherOf Where would you put the arrow? father child
7
ER Diagrams 3 Person id name age FatherOf father child
8
ER Diagrams 4 Director id name produced Movie title Actor idname What does this mean? A movie has at most one actor and one director
9
What does this diagram mean? Director id name Directed Movie title A movie has exactly one director. A director directs at least one movie. ER Diagrams 5
10
Copy copy numbercondition Copy Of Borrowed Person id Book title author isbn Owned By Library name ER Diagrams 6
11
snopno S1 S2 S3 S4 P1 P2 P3 P4 P1 P2 P4 P2 pno sno = Division 1
12
snopno S1 S2 S3 S4 P1 P2 P3 P4 P1 P2 P4 P2 pno sno = Division 1 S1 S2 S3 S4
13
snopno S1 S2 S3 S4 P1 P2 P3 P4 P1 P2 P4 P2 P4 pno sno = Division 2
14
snopno S1 S2 S3 S4 P1 P2 P3 P4 P1 P2 P4 P2 P4 pno sno = Division 2 S1 S4
15
snopno S1 S2 S3 S4 P1 P2 P3 P4 P1 P2 P4 P1 P2 P4 pno sno = Division 3
16
snopno S1 S2 S3 S4 P1 P2 P3 P4 P1 P2 P4 pno sno = Division 3 S1 P1 P2 P4
17
SQL Aggregation 1 SELECT B.bid, COUNT(*) FROM Boats B, Reserves R WHERE R.bid=B.bid and B.color=‘red’ GROUP BY B.bid What does this query return? Tuples: (id of a reserved red boat, # of reservations of the red boat)
18
SELECT B.bid, COUNT(*) FROM Boats B, Reserves R WHERE R.bid=B.bid GROUP BY B.bid, B.color HAVING B.color=‘red’ SQL Aggregation 2 What if we put the condition into the HAVING clause? We have also to put the color in the grouping list!
19
Aggregation 3 SELECT color FROM Boats B GROUP BY color HAVING max(count(bid)) What is wrong with this? How would you fix it? The Color for which there are the most boats
20
SELECT color FROM Boats B GROUP BY color HAVING count(bid) >= ALL (SELECT count(bid) FROM Boats GROUP BY Color) SQL Aggregation 3 The Color for which there are the most boats
21
Compute Closure(X, F) C := X while there is a V W in F such that (V C)and (W C) do C := C W return C Attribute Closure 1
22
R=ABCDE F={AB C, CE B, D A, BC E} Attribute Closure 2 {A} + = {A,B} + = {B,D} + = {A} {A,B,C,E} {A,B,C,D,E}
23
IsDependencyPreserving(F,R 1…k ) for each X->Y in F do if not IsPreserved(X,Y,R 1…k ) return false return true Dependency Preservation 1a
24
/* check if X->Y is preserved */ IsPreserved(X,Y,R 1…k ) Z:=X while changes to Z occur do for i=1 to k do Z:= Z ((Z R i ) + R i ) if Y Z return true else return false Dependency Preservation 1b
25
Is the following decomposition dependency preserving? R = ABCDE F = {A -> ABCDE, BC -> A, DE -> C} R 1 = ABDE, R 2 = DEC Dependency Preservation 2 No! BC->A is not preserved
26
R = ABC. For each F below, decide whether R is in BCNF/3NF: Normal Forms F = {} F = {A -> B} F = {A -> B, A -> C} F = {A -> B, B -> C} F = {A -> B, BC -> A}
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.