Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC-310 Database Systems

Similar presentations


Presentation on theme: "CPSC-310 Database Systems"— Presentation transcript:

1 CPSC-310 Database Systems
Professor Jianer Chen Room 315C HRBB Lecture #8

2 BCNF and 3NF

3 BCNF and 3NF BCNF  3NF 3NF BCNF

4 eliminating FD redundancies
BCNF and 3NF BCNF  3NF 3NF BCNF Property 3NF BCNF eliminating FD redundancies no (but most) yes recoverable preserving FDs

5 eliminating FD redundancies
BCNF and 3NF BCNF  3NF 3NF BCNF Property 3NF BCNF ?? eliminating FD redundancies no (but most) yes recoverable preserving FDs

6 eliminating FD redundancies
BCNF and 3NF BCNF  3NF 3NF BCNF Property 3NF BCNF Not Exist! eliminating FD redundancies no (but most) yes recoverable preserving FDs

7 eliminating FD redundancies
BCNF and 3NF BCNF  3NF 3NF BCNF Property 3NF BCNF Not Exist! eliminating FD redundancies no (but most) yes recoverable preserving FDs

8 eliminating FD redundancies
BCNF and 3NF BCNF  3NF 3NF BCNF Property 3NF BCNF Not Exist! eliminating FD redundancies no (but most) yes recoverable preserving FDs Would BCNF be sufficient to eliminate other kind of redundancies?

9 Example of a bad relation in BCNF

10 Example of a bad relation in BCNF
Suppose that we have a relation that lists the teacher- student relationship for each person. That is, for a person p, the relation gives all teachers who ever taught p and all students who were ever taught by p. For example, suppose that David and Jeff taught Kevin, while Kevin taught Michael, Jason, and Tom. Then the relation should contain tuples:

11 Example of a bad relation in BCNF
Suppose that we have a relation that lists the teacher- student relationship for each person. That is, for a person p, the relation gives all teachers who ever taught p and all students who were ever taught by p. For example, suppose that David and Jeff taught Kevin, while Kevin taught Michael, Jason, and Tom. Then the relation should contain tuples: person teacher student Kevin David Michael Jason Tom Jeff ……

12 Example of a bad relation in BCNF
Suppose that we have a relation that lists the teacher- student relationship for each person. That is, for a person p, the relation gives all teachers who ever taught p and all students who were ever taught by p. For example, suppose that David and Jeff taught Kevin, while Kevin taught Michael, Jason, and Tom. Then the relation should contain tuples: There are some obvious redundancies: suppose Kevin has n teachers and m students, then there will be n*m tuples for Kevin! On the other hand, it indeed needs no more than n+m (smaller) tuples to record all information about Kevin’s teachers and students. person teacher student Kevin David Michael Jason Tom Jeff ……

13 Example of a bad relation in BCNF
Suppose that we have a relation that lists the teacher- student relationship for each person. That is, for a person p, the relation gives all teachers who ever taught p and all students who were ever taught by p. For example, suppose that David and Jeff taught Kevin, while Kevin taught Michael, Jason, and Tom. Then the relation should contain tuples: There are some obvious redundancies: suppose Kevin has n teachers and m students, then there will be n*m tuples for Kevin! On the other hand, it indeed needs no more than n+m (smaller) tuples to record all information about Kevin’s teachers and students. On the other hand, the relation is in BCNF: the only key is {person, teacher, student} so there is no BCNF violators. person teacher student Kevin David Michael Jason Tom Jeff ……

14 Definition of MVD MVD captures redundancy that FD’s can’t

15 Definition of MVD MVD captures redundancy that FD’s can’t
A multivalued dependency (MVD) X↠Y on a relation R says that if two tuples of R agree on all the attributes of X, then by swapping their components in Y, we still get tuples in R, i.e., for each value of X, the values of Y are independent of the values of R\(X∪Y).

16 Definition of MVD MVD captures redundancy that FD’s can’t
A multivalued dependency (MVD) X↠Y on a relation R says that if two tuples of R agree on all the attributes of X, then by swapping their components in Y, we still get tuples in R, i.e., for each value of X, the values of Y are independent of the values of R\(X∪Y). person teacher student Kevin David Michael Jason Tom Jeff ……

17 Definition of MVD MVD captures redundancy that FD’s can’t
A multivalued dependency (MVD) X↠Y on a relation R says that if two tuples of R agree on all the attributes of X, then by swapping their components in Y, we still get tuples in R, i.e., for each value of X, the values of Y are independent of the values of R\(X∪Y). person teacher student Kevin David Michael Jason Tom Jeff ……

18 Definition of MVD MVD captures redundancy that FD’s can’t
A multivalued dependency (MVD) X↠Y on a relation R says that if two tuples of R agree on all the attributes of X, then by swapping their components in Y, we still get tuples in R, i.e., for each value of X, the values of Y are independent of the values of R\(X∪Y). person teacher student Kevin David Michael Jason Tom Jeff ……

19 Definition of MVD MVD captures redundancy that FD’s can’t
A multivalued dependency (MVD) X↠Y on a relation R says that if two tuples of R agree on all the attributes of X, then by swapping their components in Y, we still get tuples in R, i.e., for each value of X, the values of Y are independent of the values of R\(X∪Y). person teacher student Kevin David Michael Jason Tom Jeff ……

20 Definition of MVD MVD captures redundancy that FD’s can’t
A multivalued dependency (MVD) X↠Y on a relation R says that if two tuples of R agree on all the attributes of X, then by swapping their components in Y, we still get tuples in R, i.e., for each value of X, the values of Y are independent of the values of R\(X∪Y). person teacher student Kevin David Michael Jason Tom Jeff …… Thus, person ↠ teacher

21 Another Definition of MVDs

22 Another Definition of MVDs
Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW.

23 Another Definition of MVDs
Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. x

24 Another Definition of MVDs
Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. VY VW x y1 yp w1 wq

25 Another Definition of MVDs
Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. VY VW x R y1 yp w1 wq . x y1 w1 yi wk yp wq

26 Another Definition of MVDs
Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. VY VW x R Look at the example we discussed.

27 Another Definition of MVDs
Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. VY VW Kevin R Look at the example we discussed.

28 Another Definition of MVDs
Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. VY VW Kevin R David Jeff Michael Jason Tom Look at the example we discussed.

29 Another Definition of MVDs
Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. VY VW Kevin R David Jeff Michael Jason Tom person teacher student Kevin David Michael Jason Tom Jeff …… Look at the example we discussed.

30 Another Example Consumers(name, addr, phones, beersLiked)

31 Another Example Consumers(name, addr, phones, beersLiked)
A consumer’s phones are independent of the beers they like.

32 Another Example Consumers(name, addr, phones, beersLiked)
A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked.

33 Another Example Consumers(name, addr, phones, beersLiked)
A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations.

34 Another Example Consumers(name, addr, phones, beersLiked)
A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy.

35 Another Example Consumers(name, addr, phones, beersLiked)
A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy. name → addr is the only FD.

36 Another Example Consumers(name, addr, phones, beersLiked)
A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy. name → addr is the only FD. name addr phones beersLiked Sue a p1 b1 p2 b2

37 Another Example Consumers(name, addr, phones, beersLiked)
A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy. name → addr is the only FD. name addr phones beersLiked Sue a p1 b1 p2 b2 Then these tuples must also be in the relation.

38 Another Example Consumers(name, addr, phones, beersLiked)
A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy. name → addr is the only FD. name addr phones beersLiked Sue a p1 b1 p2 b2 If X ↠ Y X Y others Then these tuples must also be in the relation.

39 Another Example Consumers(name, addr, phones, beersLiked)
A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy. name → addr is the only FD. name addr phones beersLiked Sue a p1 b1 p2 b2 If X ↠ Y X Y others equal Then these tuples must also be in the relation.

40 Another Example Consumers(name, addr, phones, beersLiked)
A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy. name → addr is the only FD. name addr phones beersLiked Sue a p1 b1 p2 b2 If X ↠ Y X Y others equal exchange Then these tuples must also be in the relation.

41 MVD Rules Every FD is an MVD (promotion).

42 MVD Rules Every FD is an MVD (promotion).
* If X→Y, then swapping Y’s between two tuples that agree on X doesn’t change the tuples.

43 MVD Rules Every FD is an MVD (promotion).
* If X→Y, then swapping Y’s between two tuples that agree on X doesn’t change the tuples. * Therefore, the “new” tuples are surely in the relation, and we know X ↠ Y.

44 MVD Rules Every FD is an MVD (promotion).
* If X→Y, then swapping Y’s between two tuples that agree on X doesn’t change the tuples. * Therefore, the “new” tuples are surely in the relation, and we know X ↠ Y. Transitiveness: If X↠Y, and Y↠Z, then X↠Z.

45 MVD Rules Every FD is an MVD (promotion).
* If X→Y, then swapping Y’s between two tuples that agree on X doesn’t change the tuples. * Therefore, the “new” tuples are surely in the relation, and we know X ↠ Y. Transitiveness: If X↠Y, and Y↠Z, then X↠Z. Complementation: If X↠Y, and Z is all the other attributes, then X↠Z.

46 However, Splitting Doesn’t Hold
Like FD’s, we cannot generally split the left side of an MVD.

47 However, Splitting Doesn’t Hold
Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side.

48 However, Splitting Doesn’t Hold
Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf)

49 However, Splitting Doesn’t Hold
Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf) * A drinker can have several phones, with the number divided between areaCode and phone (last 7 digits).

50 However, Splitting Doesn’t Hold
Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf) * A drinker can have several phones, with the number divided between areaCode and phone (last 7 digits). * A drinker can like several beers, each with its own manufacturer.

51 However, Splitting Doesn’t Hold
Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf) Since the areaCode-phone combinations for a drinker are independent of the beersLiked-manf combinations, we expect that the following MVD’s hold:

52 However, Splitting Doesn’t Hold
Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf) Since the areaCode-phone combinations for a drinker are independent of the beersLiked-manf combinations, we expect that the following MVD’s hold: name ↠ areaCode phone name ↠ beersLiked manf

53 However, Splitting Doesn’t Hold
Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf) Since the areaCode-phone combinations for a drinker are independent of the beersLiked-manf combinations, we expect that the following MVD’s hold: name ↠ areaCode phone name ↠ beersLiked manf name areaCode phone beersLiked manf Sue 650 Bud A.B. WickedAle Peter’s 415

54 However, Splitting Doesn’t Hold
Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf) Since the areaCode-phone combinations for a drinker are independent of the beersLiked-manf combinations, we expect that the following MVD’s hold: name ↠ areaCode phone name ↠ beersLiked manf name areaCode phone beersLiked manf Sue 650 Bud A.B. WickedAle Peter’s 415 However, we cannot swap area codes or phones by themselves. That is, neither name↠areaCode nor name↠phone holds for this relation.

55 Fourth Normal Form

56 Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF.

57 Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation.

58 Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey.

59 Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey. Nontrivial MVD X ↠Y means that: * Y is not a subset of X, and * X and Y are not, together, all the attributes.

60 Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey. Nontrivial MVD X ↠Y means that: * Y is not a subset of X, and * X and Y are not, together, all the attributes. Note that the definition of “superkey” still depends on FD’s only.

61 Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey. BCNF versus 4NF:

62 Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey. BCNF versus 4NF: * FD X→Y implies MVD X ↠Y. Thus, if R is in 4NF, it is in BCNF. a BCNF violation is a 4NF violation

63 Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey. BCNF versus 4NF: * FD X→Y implies MVD X ↠Y. Thus, if R is in 4NF, it is in BCNF. a BCNF violation is a 4NF violation * But R could be in BCNF and not 4NF.

64 Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey. BCNF versus 4NF: * FD X→Y implies MVD X ↠Y. Thus, if R is in 4NF, it is in BCNF. a BCNF violation is a 4NF violation * But R could be in BCNF and not 4NF. * Thus, 4NF  BCNF

65 Decomposition into 4NF

66 Decomposition into 4NF Algorithm 4NF(R, T)
Input: A relation R and its FDs T and MVFs F Output: A collection C of relations in 4NF 1. C = ; C’ = {(R, T, F)}; 2. While C’   Do 2.1 Pick (R’, T’, F’) from C’; \\ remove from C’ 2.2 If (R’, T’, F’) has a 4NF violator X↠Y; 2.3 Then decompose (R’, T’, F’) into: (R1, T1, F1) where R1= X⋃Y(R’); (R2, T2, F2) where R2= X⋃W(R’); \\ where W is the set of attributes of R’ not in \\ X⋃Y, (T1, F1) and (T2, F2) are the FDs and \\ MVFs (T’, F’) of R’ projected on R1 and R2 Add (R1, T1, F1) and (R2, T2, F2) to C’; 2.4 Else Add (R’, T’, F’) to C; 3. Output C.

67 Decomposition into 4NF Remarks. Algorithm 4NF(R, T)
Input: A relation R and its FDs T and MVFs F Output: A collection C of relations in 4NF 1. C = ; C’ = {(R, T, F)}; 2. While C’   Do 2.1 Pick (R’, T’, F’) from C’; \\ remove from C’ 2.2 If (R’, T’, F’) has a 4NF violator X↠Y; 2.3 Then decompose (R’, T’, F’) into: (R1, T1, F1) where R1= X⋃Y(R’); (R2, T2, F2) where R2= X⋃W(R’); \\ where W is the set of attributes of R’ not in \\ X⋃Y, (T1, F1) and (T2, F2) are the FDs and \\ MVFs (T’, F’) of R’ projected on R1 and R2 Add (R1, T1, F1) and (R2, T2, F2) to C’; 2.4 Else Add (R’, T’, F’) to C; 3. Output C.

68 Decomposition into 4NF Remarks.
1. Very similar to the algorithm for BCNF; Algorithm 4NF(R, T) Input: A relation R and its FDs T and MVFs F Output: A collection C of relations in 4NF 1. C = ; C’ = {(R, T, F)}; 2. While C’   Do 2.1 Pick (R’, T’, F’) from C’; \\ remove from C’ 2.2 If (R’, T’, F’) has a 4NF violator X↠Y; 2.3 Then decompose (R’, T’, F’) into: (R1, T1, F1) where R1= X⋃Y(R’); (R2, T2, F2) where R2= X⋃W(R’); \\ where W is the set of attributes of R’ not in \\ X⋃Y, (T1, F1) and (T2, F2) are the FDs and \\ MVFs (T’, F’) of R’ projected on R1 and R2 Add (R1, T1, F1) and (R2, T2, F2) to C’; 2.4 Else Add (R’, T’, F’) to C; 3. Output C.

69 Decomposition into 4NF Remarks.
1. Very similar to the algorithm for BCNF; 2. The projections (T1, F1) and (T2, F2) of (T’, F’) of R’ on R1 and R2 can be constructed; Algorithm 4NF(R, T) Input: A relation R and its FDs T and MVFs F Output: A collection C of relations in 4NF 1. C = ; C’ = {(R, T, F)}; 2. While C’   Do 2.1 Pick (R’, T’, F’) from C’; \\ remove from C’ 2.2 If (R’, T’, F’) has a 4NF violator X↠Y; 2.3 Then decompose (R’, T’, F’) into: (R1, T1, F1) where R1= X⋃Y(R’); (R2, T2, F2) where R2= X⋃W(R’); \\ where W is the set of attributes of R’ not in \\ X⋃Y, (T1, F1) and (T2, F2) are the FDs and \\ MVFs (T’, F’) of R’ projected on R1 and R2 Add (R1, T1, F1) and (R2, T2, F2) to C’; 2.4 Else Add (R’, T’, F’) to C; 3. Output C.

70 Decomposition into 4NF Remarks.
1. Very similar to the algorithm for BCNF; 2. The projections (T1, F1) and (T2, F2) of (T’, F’) of R’ on R1 and R2 can be constructed; 3. It can be proved that the algorithm produces relations from which the original relation is re-constructible; Algorithm 4NF(R, T) Input: A relation R and its FDs T and MVFs F Output: A collection C of relations in 4NF 1. C = ; C’ = {(R, T, F)}; 2. While C’   Do 2.1 Pick (R’, T’, F’) from C’; \\ remove from C’ 2.2 If (R’, T’, F’) has a 4NF violator X↠Y; 2.3 Then decompose (R’, T’, F’) into: (R1, T1, F1) where R1= X⋃Y(R’); (R2, T2, F2) where R2= X⋃W(R’); \\ where W is the set of attributes of R’ not in \\ X⋃Y, (T1, F1) and (T2, F2) are the FDs and \\ MVFs (T’, F’) of R’ projected on R1 and R2 Add (R1, T1, F1) and (R2, T2, F2) to C’; 2.4 Else Add (R’, T’, F’) to C; 3. Output C.

71 Decomposition into 4NF Remarks.
1. Very similar to the algorithm for BCNF; 2. The projections (T1, F1) and (T2, F2) of (T’, F’) of R’ on R1 and R2 can be constructed; 3. It can be proved that the algorithm produces relations from which the original relation is re-constructible; 4. The algorithm eliminates BCNF and MVF violations. Algorithm 4NF(R, T) Input: A relation R and its FDs T and MVFs F Output: A collection C of relations in 4NF 1. C = ; C’ = {(R, T, F)}; 2. While C’   Do 2.1 Pick (R’, T’, F’) from C’; \\ remove from C’ 2.2 If (R’, T’, F’) has a 4NF violator X↠Y; 2.3 Then decompose (R’, T’, F’) into: (R1, T1, F1) where R1= X⋃Y(R’); (R2, T2, F2) where R2= X⋃W(R’); \\ where W is the set of attributes of R’ not in \\ X⋃Y, (T1, F1) and (T2, F2) are the FDs and \\ MVFs (T’, F’) of R’ projected on R1 and R2 Add (R1, T1, F1) and (R2, T2, F2) to C’; 2.4 Else Add (R’, T’, F’) to C; 3. Output C.

72 Example

73 Example Consumers(name, addr, phones, candiesLiked)

74 Example Consumers(name, addr, phones, candiesLiked) FD: name → addr
MVD’s: name ↠ phones, name ↠ candiesLiked Key is {name, phones, candiesLiked}. All dependencies violate 4NF.

75 Example Consumers(name, addr, phones, candiesLiked) FD: name → addr
MVD’s: name ↠ phones, name ↠ candiesLiked Key is {name, phones, candiesLiked}. All dependencies violate 4NF. Decompose using name → addr:

76 Example Consumers(name, addr, phones, candiesLiked) FD: name → addr
MVD’s: name ↠ phones, name ↠ candiesLiked Key is {name, phones, candiesLiked}. All dependencies violate 4NF. Decompose using name → addr: Consumers1(name, addr) In 4NF; only dependency is name → addr.

77 Example Consumers(name, addr, phones, candiesLiked) FD: name → addr
MVD’s: name ↠ phones, name ↠ candiesLiked Key is {name, phones, candiesLiked}. All dependencies violate 4NF. Decompose using name → addr: Consumers1(name, addr) In 4NF; only dependency is name → addr. Consumers2(name, phones, candiesLiked)

78 Example Consumers(name, addr, phones, candiesLiked) FD: name → addr
MVD’s: name ↠ phones, name ↠ candiesLiked Key is {name, phones, candiesLiked}. All dependencies violate 4NF. Decompose using name → addr: Consumers1(name, addr) In 4NF; only dependency is name → addr. Consumers2(name, phones, candiesLiked) Not in 4NF. MVD’s name ↠ phones and name ↠ candiesLiked apply. No FD’s, so all three attributes form the key.

79 Example Consumers(name, addr, phones, candiesLiked) FD: name → addr
MVD’s: name ↠ phones, name ↠ candiesLiked Key is {name, phones, candiesLiked}. All dependencies violate 4NF. Decompose using name → addr: Consumers1(name, addr) In 4NF; only dependency is name → addr. Consumers2(name, phones, candiesLiked) Not in 4NF. MVD’s name ↠ phones and name ↠ candiesLiked apply. No FD’s, so all three attributes form the key. Either name↠phones or name↠candiesLiked gives: Consumers3(name, phones) Consumers4(name, candiesLiked)

80 Normal Form Comparisons

81 Normal Form Comparisons
3NF BCNF 4NF  BCNF  3NF 4NF

82 Normal Form Comparisons
3NF BCNF 4NF  BCNF  3NF 4NF Property 3NF BCNF 4NF eliminates FD redundancies no (most) yes eliminates MVD redundancies no preserves FDs recoverable


Download ppt "CPSC-310 Database Systems"

Similar presentations


Ads by Google