Presentation is loading. Please wait.

Presentation is loading. Please wait.

Normalization theory exercises Dr. Shiyong Lu Department of Computer Science Wayne State University ©copyright 2007, all rights reserved.

Similar presentations


Presentation on theme: "Normalization theory exercises Dr. Shiyong Lu Department of Computer Science Wayne State University ©copyright 2007, all rights reserved."— Presentation transcript:

1 Normalization theory exercises Dr. Shiyong Lu Department of Computer Science Wayne State University Shiyong@wayne.edu ©copyright 2007, all rights reserved

2 Database schema for the exercises Consider schema(R, F), where R=ABCDE, F={E→AC, A→B, BD→E, CE→A}

3 Exercise 1 Consider schema(R, F), where R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Find all the keys of the relation.

4 Solution Consider schema(R, F), where R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Step 1: for X to be a key, X + F =ABCDE take the union of the right hand side, we got ABCE, therefore D must be part of a key since otherwise, D  X + F ?

5 Solution Consider schema(R, F), where R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Step 2: is D already a key? We have D + F =D, so no. Try to calculate the attribute closure of DA, DB, DC, DE.

6 Solution Consider schema(R, F), where R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Step 3: DA + F = DABEC, DB + F = DBEAC DC + F = DC, DE + F = DEACB, so DA, DB, DE are keys, what about DC? Continue to try DCA, DCB, DCE?

7 Exercise 2 Consider schema(R, F), where R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Decompose the schema into a set of BCNF schemas.

8 Solution R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Step 1: Pick up a dependency that violates BCNF requirements. (DA, DB, DE are keys). Pick up E→AC. Decompose: R1 = EAC, F1 = {E→AC, CE→A} R2=BDE, F2 = {BD→E} Both of them are now in BCNF! Why?

9 Exercise 3 Consider schema(R, F), where R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Is this decomposition lossless? Is it dependency-preserving?

10 Solution R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Yes, it is lossless since the intersection of the two relations is a superkey of one of the relations. Not dependency preserving, because F1  F2 ={E→AC, BD→E, CE→A} and A→B  ( F1  F2) + ! May I drop the above +?

11 Exercise 4 Consider schema(R, F), where R=ABCDE, F={E→AC, A→B, BD→E, CE→A} What is the attribute closure of ACD?

12 Solution R=ABCDE, F={E→AC, A→B, BD→E, CE→A} [ACD + F ] 1 = ACD [ACD + F ] 2 = ACDB, after applying A→B [ACD + F ] 3 = ACDBE, after applying BD→E Done! [ACD + F ] = ABCDE, ACD is a superkey? Can we conclude ACD is a key?

13 Exercise 5 Consider schema(R, F), where R=ABCDE, F={E→AC, A→B, BD→E, CE→A} What is the minimal cover of F?

14 Solution R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Step 1: minimize the right hand side F1={E→A, E → C, A→B, BD→E, CE→A}

15 Solution R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Step 2: minimize the left hand side of F1 F1={E→A, E → C, A→B, BD→E, CE→A} B + F1 = B, D + F1 = D, C + F1 = D, E + F1 = EAC, so the last dependency can be minimized to E→A. We got F2 = {E→A, E → C, A→B, BD→E}

16 Solution R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Step 3: F2 = {E→A, E → C, A→B, BD→E}, can we eliminate any dependency from F2? Consider eliminating E→A, see if E→A  (F2- E→A) +. Since E + F2-f =EC, we cannot eliminate E→A. How about other dependencies? None. So F2 is the minimal cover!

17 Exercise 6 Consider schema(R, F), where R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Decompose the schema into a set of 3NF schemas.

18 Solution R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Step 1: we got the minimal cover as F2 = {E→A, E → C, A→B, BD→E}, Step 2: grouping by left hands U1 = {E→A, E → C}, U2={A→B}, U3 ={ BD→E} Step 3: R1=(EAC, E→A, E → C), R2 = (AB, A→B), R3=(BDE, BD→E), do we need step 4?

19 Exercise 7 Consider schema(R, F), where R=ABCDE, F={E→AC, A→B, BD→E, CE→A} Is the decomposition lossless? Is it functional dependency preserving, why?


Download ppt "Normalization theory exercises Dr. Shiyong Lu Department of Computer Science Wayne State University ©copyright 2007, all rights reserved."

Similar presentations


Ads by Google