Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts.

Similar presentations


Presentation on theme: "Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts."— Presentation transcript:

1 Chapter 7: Relational Database Design

2 ©Silberschatz, Korth and Sudarshan7.2Database System Concepts

3 ©Silberschatz, Korth and Sudarshan7.3Database System Concepts

4 ©Silberschatz, Korth and Sudarshan7.4Database System Concepts

5 ©Silberschatz, Korth and Sudarshan7.5Database System Concepts Example R = (student_id, student_name, course_id, course_name ) F = {student_id  student_name, course_id  course_name } { student_id, course_id } is a candidate key. F c = F R 1 = ( student_id, student_name ) R 2 = ( course_id, course_name ) R 3 = ( student_id, course_id)

6 ©Silberschatz, Korth and Sudarshan7.6Database System Concepts

7 ©Silberschatz, Korth and Sudarshan7.7Database System Concepts Example 2 R = ( A, B, C ) F = { A  BC, B  C } R is not in 3NF F c = { A  B, B  C } Decomposition into: R1 = ( A, B ), R2 = ( B, C ) R1 and R2 are in 3NF

8 ©Silberschatz, Korth and Sudarshan7.8Database System Concepts BCNF VS 3NF always possible to decompose a relation into relations in 3NF and  the decomposition is lossless  dependencies are preserved always possible to decompose a relation into relations in BCNF and  the decomposition is lossless  may not be possible to preserve dependencies

9 ©Silberschatz, Korth and Sudarshan7.9Database System Concepts Candidate keys are (sid, part_id) and (sname, part_id). { sid, part_id }  qty { sname, part_id }  qty sid  sname sname  sid The relation is in 3NF: For sid  sname, … sname is in a candidate key. For sname  sid, … sid is in a candidate key. However, this leads to redundancy and loss of information More Examples SSP sid sname part_id qty

10 ©Silberschatz, Korth and Sudarshan7.10Database System Concepts If we decompose the schema into R 1 = ( sid, sname ), R 2 = ( sid, part_id, qty ) These are in BCNF. The decomposition is dependency preserving. { sname, part_id }  qty can be deduced from  sname  sid(given)  { sname, part_id }  { sid, part_id }(augmentation on (1))  { sid, part_id }  qty(given) and finally transitivity on (2) and (3). SSP sid sname part_id qty

11 ©Silberschatz, Korth and Sudarshan7.11Database System Concepts At a city, for a certain part, the supplier is unique: city part_id  sid. Also, sid  city The relation is not in BCNF: sid  city is not trivial, and … sid is not a superkey It is in 3NF: sid  city … city is in the candidate key of { city, part_id }. If we decompose into ( sid, city ) and ( sid, part_id ) we have BCNF, however { city, part_id }  sid will not be preserved. SUPPLY part_id SUPPLY city part_id sid city sid More Examples

12 ©Silberschatz, Korth and Sudarshan7.12Database System Concepts Design Goals Goal for a relational database design is:  BCNF  lossless join  Dependency preservation If we cannot achieve this, we accept:  3NF  lossless join  Dependency preservation

13 ©Silberschatz, Korth and Sudarshan7.13Database System Concepts

14 ©Silberschatz, Korth and Sudarshan7.14Database System Concepts

15 ©Silberschatz, Korth and Sudarshan7.15Database System Concepts Multivalued Dependencies There are database schemas in BCNF that do not seem to be sufficiently normalized Consider a database classes(course, teacher, book) such that (c,t,b)  classes means that t is qualified to teach c, and b is a required textbook for c The database is supposed to list for each course the set of teachers any one of which can be the course’s instructor, and the set of books, all of which are required for the course (no matter who teaches it).

16 ©Silberschatz, Korth and Sudarshan7.16Database System Concepts There are no non-trivial functional dependencies and therefore the relation is in BCNF Insertion anomalies – i.e., if Sara is a new teacher that can teach database, two tuples need to be inserted (database, Sara, DB Concepts) (database, Sara, Ullman) courseteacherbook database operating systems Avi Hank Sudarshan Avi Jim DB Concepts Ullman DB Concepts Ullman DB Concepts Ullman OS Concepts Shaw OS Concepts Shaw classes Multivalued Dependencies (Cont.)

17 ©Silberschatz, Korth and Sudarshan7.17Database System Concepts Therefore, it is better to decompose classes into: courseteacher database operating systems Avi Hank Sudarshan Avi Jim teaches coursebook database operating systems DB Concepts Ullman OS Concepts Shaw text We shall see that these two relations are in Fourth Normal Form (4NF) Multivalued Dependencies (Cont.)

18 ©Silberschatz, Korth and Sudarshan7.18Database System Concepts Multivalued Dependencies (MVDs) Let R be a relation schema and let   R and   R. The multivalued dependency    holds on R if in any legal relation r(R), for all pairs for tuples t 1 and t 2 in r such that t 1 [  ] = t 2 [  ], there exist tuples t 3 and t 4 in r such that: t 1 [  ] = t 2 [  ] = t 3 [  ] = t 4 [  ] t 3 [  ] = t 1 [  ] t 3 [R –  ] = t 2 [R –  ] t 4 [  ] = t 2 [  ] t 4 [R –  ] = t 1 [R –  ]

19 ©Silberschatz, Korth and Sudarshan7.19Database System Concepts

20 ©Silberschatz, Korth and Sudarshan7.20Database System Concepts MVD (Cont.) Tabular representation of   

21 ©Silberschatz, Korth and Sudarshan7.21Database System Concepts

22 ©Silberschatz, Korth and Sudarshan7.22Database System Concepts

23 ©Silberschatz, Korth and Sudarshan7.23Database System Concepts

24 ©Silberschatz, Korth and Sudarshan7.24Database System Concepts

25 ©Silberschatz, Korth and Sudarshan7.25Database System Concepts

26 ©Silberschatz, Korth and Sudarshan7.26Database System Concepts

27 ©Silberschatz, Korth and Sudarshan7.27Database System Concepts

28 ©Silberschatz, Korth and Sudarshan7.28Database System Concepts X ->> Y is trivial if (a)Y  X or (b)Y U X = R

29 ©Silberschatz, Korth and Sudarshan7.29Database System Concepts

30 ©Silberschatz, Korth and Sudarshan7.30Database System Concepts

31 ©Silberschatz, Korth and Sudarshan7.31Database System Concepts


Download ppt "Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts."

Similar presentations


Ads by Google