80 likes | 316 Views
Classroom Exercise: Normalization. Consider the relation R(A,B,C,D) with these given FDs: AB -> C C -> D D -> A Compute all nontrivial FDs that follow from these. Compute the key(s) for R. What are all the superkeys? What are all the BCNF violations? Decompose R into BCNF.
E N D
Classroom Exercise: Normalization • Consider the relation R(A,B,C,D) with these given FDs: • AB -> C • C -> D • D -> A • Compute all nontrivial FDs that follow from these. • Compute the key(s) for R. • What are all the superkeys? • What are all the BCNF violations? • Decompose R into BCNF. • What are all the 3NF violations (before decomposing into BCNF)? • Decompose R into 3NF.
Consider the relation R(A,B,C,D) with these given FDs: • AB -> C C -> D D -> A • Compute all nontrivial FDs that follow from these. 1. For each set of attributes X, compute X+: A+ = A; B+ = B; C+ = CDA; D+ = DA; AB+ = ABCD; AC+ = ACD; AD+ = AD; BC+ = BCDA; BD+ = BDAC; CD+ = CDA; ABC+ = ABCD; ABD+ = ABCD; ACD+ = ACD; BCD+ = BCDA 2. New FDs are of form X -> A for all A in X+; drop trivial ones A -> A; B -> B; C -> CDA; D -> DA; AB -> ABCD; AC -> ACD; AD -> AD; BC -> BCDA; BD -> BDA; CD -> CDA; ABC -> ABCD; ABD -> ABCD; ACD -> ACD; BCD -> BCDA 3. Drop redundant ones (if we have X -> A, don't need XY -> A): C -> D; C -> A; D -> A, AB -> C; AB -> D; AC -> D; BC -> D; BC -> A; BD -> A; CD -> A; ABC -> D; ABD -> C; BCD -> A
So the relation R(A,B,C,D) has these FDs: • C -> D (given originally) • C -> A • D -> A (given originally) • AB -> C (given originally) • AB -> D • Compute the key(s) for R. • three keys: AB, BC, and BD • What are all the superkeys? • every superset of a key: ABC, ABD, BCD, ABCD • What are all the BCNF violations? • any FD whose LHS does not contain a key: C -> D; C -> A; D -> A
Decompose R into BCNF. • Start with violating FD X -> A. • Compute X+. • New relations are R1 with attributes X+ and R2 with attributes R - X+ U X. • Project R's FD's onto R1 and R2. • Check if need to decompose some more. • Let's start with C -> D. • Compute C+ = CDA. • New relation R1(C,D,A): • FD's for R1: C -> D, C -> A, D -> A • key for R1: C • D -> A violates BCNF, need to decompose • New relation R2(B,C): • FD's for R2: none • key for R2: BC • in BCNF
Decompose R1(C,D,A) with FD's C -> D; C -> A; D -> A and key C • Start with D -> A: • Compute D+ = DA • new relation R3(D,A) with FD D -> A and key D. Is in BCNF. • new relation R4(C,D) with FD C -> D and key C. Is in BCNF. • Final set of BCNF relation schemas: • R2(B,C), R3(D,A), and R4(C,D)
What about decomposing into 3NF? • Original relation is R(A,B,C,D) • We already discovered the FD's: • C -> D (given originally) • C -> A • D -> A (given originally) • AB -> C (given originally) • AB -> D • We already discovered the keys: AB, BC, BD • What are the 3NF violations (LHS does not contain a key AND RHS is not part of a key)? • None! Every attribute is part of a key, so no FD violates FD. Thus no decomposition is necessary.