Homework #2 Answers 1. Exercise 3.2.1 page 75 Customers(ssNo, name, address, phone) Flights(number, day, aircraft) Bookings(ssNo, number, day, row, seat) Being a weak entity set, Bookings' relation has the keys for Customers and Flights and Bookings' own attributes. Notice that the relations obtained from the toCust and toFlt relationships are unnecessary. They are: toCust(ssNo, ssNo1, number, day) toFlt(ssNo, number, day, number1, day1) That is, for toCust, the key of Customers is paired with the key for Bookings. Since both include ssNo, this attribute is repeated with two different names, ssNo and ssNo1. A similar situation exists for toFlt. 2. Exercise 3.5.1 page 100 Exercise 3.5.1(a) We could try inference rules to deduce new dependencies until we are satisfied we have them all. A more systematic way is to consider the closures of all 15 nonempty sets of attributes. For the single attributes we have A+ = A, B+ = B, C+ = ACD, and D+ = AD. Thus, the only new dependency we get with a single attribute on the left is C->A. Now consider pairs of attributes: AB+ = ABCD, so we get new dependency AB->D. AC+ = ACD, and AC->D is nontrivial. AD+ = AD, so nothing new. BC+ = ABCD, so we get BC->A, and BC->D. BD+ = ABCD, giving us BD->A and BD->C. CD+ = ACD, giving CD->A. For the triples of attributes, ACD+ = ACD, but the closures of the other sets are each ABCD. Thus, we get new dependencies ABC->D, ABD->C, and BCD->A. Since ABCD+ = ABCD, we get no new dependencies. The collection of 11 new dependencies mentioned above is: C->A, AB->D, AC->D, BC>A, BC->D, BD->A, BD->C, CD->A, ABC->D, ABD->C, and BCD->A. Exercise 3.5.1(b) From the analysis of closures above, we find that AB, BC, and BD are keys. All other sets either do not have ABCD as the closure or contain one of these three sets. Exercise 3.5.1(c) The superkeys are all those that contain one of those three keys. That is, a superkey that is not a key must contain B and more than one of A, C, and D. Thus, the (proper) superkeys are ABC, ABD, BCD, and ABCD. 3. Exercise 3.5.2 i a. A->B, A->C, A->D, B->C, B->D, AB->C, AB->D, AC->B, AC->D, ABD->C, ABC->D, ACD->B b. A c. AB, AC, AD, ABC, ABD, ACD, ABCD 4. Exercise 3.5.4 a. A B 0 3 1 3 b. Let A=social security number and B=number of children and C=address. Then, AB->C and A->C but it is not true that B->C. A B C 1 3 5 1 4 5 2 5 6 c. For a table of classes for a given quarter: A=day and time, B=room number, and C=course number A 1 1 2 B 4 5 4 C 5 6 7 5. Exercise 3.5.10 (a) We need to compute the closures of all subsets of {ABC}, although there is no need to think about the empty set or the set of all three attributes. Here are the calculations for the remaining six sets: A+ = A B+ = B C+ = ACE AB+ = ABCDE AC+ = ACE BC+ = ABCDE We ignore D and E, so a basis for the resulting functional dependencies for ABC are: C->A and AB->C. Note that BC->A is true, but follows logically from C->A, and therefore may be omitted from our list. 6. Exercise 3.6.1 (a) and (b) page 117 Exercise 3.6.1(a) In the solution to Exercise 3.5.1 we found that there are 14 nontrivial dependencies, including the three given ones and 11 derived dependencies. These are: C->A, C->D, D>A, AB->D, AB-> C, AC->D, BC->A, BC->D, BD->A, BD->C, CD->A, ABC->D, ABD->C, and BCD->A. We also learned that the three keys were AB, BC, and BD. Thus, any dependency above that does not have one of these pairs on the left is a BCNF violation. These are: C->A, C>D, D->A, AC->D, and CD->A. One choice is to decompose using C->D. That gives us ABC and CD as decomposed relations. CD is surely in BCNF, since any two-attribute relation is. ABC is not in BCNF, since AB and BC are its only keys, but C->A is a dependency that holds in ABCD and therefore holds in ABC. We must further decompose ABC into AC and BC. Thus, the three relations of the decomposition are AC, BC, and CD. Since all attributes are in at least one key of ABCD, that relation is already in 3NF, and no decomposition is necessary. Exercise 3.6.1(b) The only key is AB. Thus, B->C and B->D are both BCNF violations. The derived FD's BD->C and BC->D are also BCNF violations. However, any other nontrivial, derived FD will have A and B on the left, and therefore will contain a key. One possible BCNF decomposition is AB and BCD. It is obtained starting with any of the four violations mentioned above. AB is the only key for AB, and B is the only key for BCD. Since there is only one key for ABCD, the 3NF violations are the same, and so is the decomposition.