Database Design and Normalization Chapter 12 (Week 13) EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 1
Multivalued Dependencies Employee Child Salary Year Hilbert Hubert $35K 1976 Hilbert Hubert $40K 1975 Gauss Gwendolyn $40K 1975 Gauss Gwendolyn $50K 1976 Gauss Greta $40K 1975 Gauss Greta $50K 1976 Pythagoras Peter $15K 1976 Pythagoras Peter $20K 1976 all key (No FD) {Gauss} X {Greta, Gwendolyn} X {$40K, 1975), ( $50K,1976)} EMPLOYEE CHILD (S,Y) independent EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 2
Example Item Department Color c 1 brown t 1 black s 1 brown d 2 green s 2 brown b 2 red b 2 yellow b 2 blue b 3 red b 3 yellow b 3 blue Inventory relation: An item is recorded iff it has a color and is used by a department. An item may have more than color. A department may use more than one item in various colors. It uses all the colors of that item. item fifi color If there is a tuple showing that an item I is sold by a department d, and there is a tuple showing that an item a color c then there is a tuple showing that item I having color is sold by department d. EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 3
Anomalies Inventory relation: - Insertion - Deletion - Update Item Department Color c 1 brown t 1 black s 1 brown d 2 green s 2 brown b 2 red b 2 yellow b 2 blue b 3 red b 3 yellow b 3 blue EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 4
Multivalued Dependencies Generalization to MVD can be defined as follows: Let X, Y1, Y2,, Yn are partition of the column names of R. The generalized MVD X Y1 Y2 Y3 Yn (which means X Yi holds for each set Yi) holds iff R is the join of its projections R1(X,Y1), R2(X,Y2), Rn(X,Yn) EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 5
4NF Theorem: An MVD x y holds for R, iff R is the join of its projections R1(x,y) and R2(x,z), where x, y and z are disjoint subsets of attributes. Since y and z are symmetrically treated so X fifi Y holds for R (X,Y,Z) iff X fifi Z holds (complementation) Theorem: A relation R is 4NF if it is in BCNF and all MVDs are FDs. In other words, for every non-trivial X fifi Y, X is a superkey of R, i.e. uniquely determines all attributes through FD. EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 6
Conversion to 4NF If X fifi Y holds for R, then decompose R by two relations (R-Y) and (X Y). Repeat the process, if desired. Example: {employee,child}, {employee, salary,year} Example: {item,color}, {item, dept} EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 7
5NF (PJ/NF) Person Skill Job P5 Comp Prog1 P1 Comp Auto1 P4 Mech Auto2 P2 Mech Auto1 Relation PERSON-USING-SKILLS-ON-JOBS is in BCNF, 4NF Job Auto requires both COMP and MECH skills Anomaly: If we delete (P1, MECH, AUTO) then we must delete (P1,COMP,AUTO) P3 Comp Auto1 EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 8
5NF (PJ/NF) PERSON-USING-SKILLS-ON-JOBS Person Skill Job P5 Comp Prog1 P1 Comp Auto1 P4 Mech Auto2 P2 Mech Auto1 P3 Comp Auto1 HAS-SKILL Person P1 P1 P2 P3 Skill Comp Mech Mech Comp NEEDS-SKILL Skill Job Comp Prog1 Comp Auto1 Mech Auto1 Mech Auto2 Person P1 P1 P1 P2 P3 Job Prog1 Auto2 Auto1 Auto1 Auto1 CAN-USE-SKILL-ON-JOB Person Skill Job P1 Comp Prog1 P1 Comp Auto1 P1 Mech Auto1 P1 Mech Auto2 P2 Mech Auto1 P2 Mech Auto2 P3 Comp Prog1 P3 Comp Auto1 ASSIGNED-TO-JOB Each relation acts as a constraint on the join of the other two relations. EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 9
5NF (PJ/NF) Definition: A relation R has JD *(X,Y,Z, ) iff R R1[x] * R2[Y] * R3[Z} * (join) where X, Y, Z etc. are subsets of attributes of R. - It specifies that every legal instance of of R should have a lossless decomposition into R1, R2, R3 Rn - An MVD is a special case of R with n=2 EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 10
Deduction and Inference About Entries S# P# J# S1 P1 J2 S1 P2 J1 S2 P2 J1 New insertion EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 11
5NF (PJ/NF) Theorem: A relation R is in P-J/NF (5NF) iff every possible JD which holds in R is the result of the candidate keys. (not any other non-key attribute) Example: S(S#,Sname,state,city) JD * ( (S#,Sname,status),(S#,city) ) JD* ( (S#,sname),(S#,status),(Sname,city) ) EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 12
5NF (PJ/NF) A relation R(A,B,C) satisfies JD*(AB,AC) (i.e. It is de-composible in 5NF) iff it satisfies the pair of MVDs A B C (MVD is a special case of JD) EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 13