### Similar presentations

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

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.

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 ?

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.

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?

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.

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?

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?

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 +?

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?

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?

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?

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}

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}

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!

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.

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?

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?