170 likes | 453 Views
Multivalued Dependencies and 4NF . Some relations can exist that are in BCNF but they have redundant data and have update anomalies The next highest normal form is 4NF 4NF is based on multivalued dependencies. Multivalued Dependencies.
E N D
Multivalued Dependencies and 4NF Some relations can exist that are in BCNF but they have redundant data and have update anomalies The next highest normal form is 4NF 4NF is based on multivalued dependencies ACS - 3902 Ron McFadyen
Multivalued Dependencies • Consider a relation R comprising attributes X U Y U Z where X, Y, Z are sets of atttributes • The multivalued dependency, X Y, exists if when two tuples exist having the same X values: • T1(x, y1, z1) and T2(x, y2, z2), • implies the two tuples • T4(x, y2, z1) and T3(x, y1, z2) also exist • The MVD X Y is also written as X Y | Z ACS - 3902 Ron McFadyen
Multivalued Dependencies • Example. • Suppose we have two one-to-many relationships: • Each employee may have many dependents • Each employee may work on many projects • For any employee, the dependants are completely independent of the projects • For a given value of ename, the values of pname are only determined by ename and not pname • For a given value of ename, the values of dname are only determined by ename and not pname • So, each ename is repeated for each pname, and each pname is repeated for each dname See figure 11.5 ACS - 3902 Ron McFadyen
Multivalued Dependencies Consider the relation EMP EMP ename pname dname Note that EMP is BCNF, and there is a lot of redundancy in EMP ACS - 3902 Ron McFadyen
Multivalued Dependencies EMP ename pname dname If (Smith, X, John) and (Smith, Y, Anna) exist, then (Smith, Y, John) and (Smith, X, Anna) exist The MVD ename pname | dname exists in EMP ACS - 3902 Ron McFadyen
Multivalued Dependencies We might have liked to have: EMP ename pname dname Smith X, Y John, Anna But 1NF does not permit multivalued attributes ACS - 3902 Ron McFadyen
Multivalued Dependencies So, instead of : EMP ename pname dname Smith X, Y John, Anna We have: EMP ename pname dname Smith X John Smith Y Anna Smith Y John Smith X Anna ACS - 3902 Ron McFadyen
Decomposing a MVD Decomposing a MVD without loss of information R X Y Z Note that if X Y | Z exists, then EMP can be decomposed into (X,Y) and (R-Y) Ra X Y X Z Rb And this is a lossless decomposition ACS - 3902 Ron McFadyen
Decomposing a MVD EMP ename pname dname As ename pname | dname exists, EMP can be decomposed into EMPa ename pname This is a lossless decomposition ename dname EMPb ACS - 3902 Ron McFadyen
4NF X Y | Z • A MVD is a trivial MVD if either • Y contained in X • X U Y = R • A trivial MVD does not specify a useful constraint for a relation • A relation R is in 4NF if and only if • it is in BCNF and • it does not contain any non-trivial MVDs ACS - 3902 Ron McFadyen
4NF • Example. • Suppose we have embassies, employees, and languages • Suppose that each embassy has languages that each employee must speak in order to work there: • Suppose our US embassy only requires English • Suppose our France embassy requires French and English • Suppose John and April work at the US embassy • Suppose David and Victor work at the France embassy ACS - 3902 Ron McFadyen
4NF Perhaps the first iteration of the design included the n-ary relationship, and the added restriction that all employees of an embassy must have each language skill of the embassy Language n works-in Employee Embassy m p Suppose we have the relation works-in employee embassy language ACS - 3902 Ron McFadyen
4NF Suppose our US embassy only requires English Suppose our France embassy requires French and English Suppose John and April work at the US embassy Suppose David and Victor work at the France embassy works-in employee embassy language John France English John France French April France English April France French David US English Victor US English ACS - 3902 Ron McFadyen
4NF • The works-in relation is BCNF, but not 4NF • There is redundancy in the relation; there are update anomalies • We can create two new 4NF relations using two projections: • works-for (employee, embassy) • required-for (embassy, language) ACS - 3902 Ron McFadyen
4NF works-for required-for employee embassy embassy language John France France English April France France French David US US English Victor US Each is in 4NF There are no redundancies ACS - 3902 Ron McFadyen
4NF Now, we might notice that the right way to have modelled is m works-for n Employee Embassy m required-for n Language ACS - 3902 Ron McFadyen