You are on page 1of 6

CS-450 Fall 2013

Dr. A. Motro

3 December 2011

Solution to Assignment No. 7: The Theory of Database Design


Problem 1. 1. Does the following relation instance satisfy the functional dependency AB C ? A B 1 1 1 1 1 2 C 2 3 3

Answer: No. The rst two tuples agree on AB but their C values are dierent. 2. List all the functional dependencies (involving the attributes A, B, C ) that are satised by the following relation instance: A B 1 1 1 2 1 4 C 2 3 3

Answer: There are 7 possibilities for the left-hand-side of functional dependencies (the number of subsets of a set of three attributes, except the empty set), and the same 7 possibilities for the right-hand-side. Altogether, there are 7 7 = 49 possible functional dependencies. Checking each of these 49 is a problem similar to part 1. Of these 49, 35 are satised by this instance (including 19 trivial functional dependencies), and 4 are not satised by this instance. The following table summarizes the answer (T means trivial): ABC AB AC BC A B C ABC T Y N Y N Y N AB T T N Y N Y N AC T Y T Y N Y Y BC T Y N T N Y N A T T T Y T Y Y B T T N T N T N C T Y T T N Y T

Problem 2. Assume a schema R = (A, B, C ) and the functional dependencies F = {A B, B C }. Prove that the functional dependency AB CB is entailed by the set F . (Hint: Try to derive this functional dependency from the functional dependencies in F using Armstrongs Axioms.) Answer: 1 AB 2 BC 3 AC 4 AB CB given given from 1 and 2 by transitivity from 3 by augmentation with B

Problem 3. The decomposition rule states that if X Y Z then X Y and X Z . Prove that the decomposition rule is sound. (Hint: Try to derive these two functional dependencies from Armstrongs Axioms.) Answer: Armstrongs Axioms allow us to infer new functional dependencies from given functional dependencies. The following argument shows that if X Y Z then X Y : 1 X Y Z given 2 Y Z Y axiom of reexivity 3 X Y from 1 and 2 by transitivity To show that if X Y Z then X Z , in the above, replace line 2 with Y Z Z , and then line 3 becomes X Z . Problem 4. Show that the following rule for functional dependencies is not sound: If X Y and Z Y then X Z . (Hint: nd a relation instance r that refutes the rule.) Answer: It is enough to construct one relation instance of one schema that satises X Y and Z Y but does not satisfy X Z . It would be nice to nd a small example. In this example we choose A for the set X , B for the set Y and C for the set Z . We only need two tuples: A 1 1 B 2 2 C 3 4

Notice that A B is satised (whenever two tuples agree on A they also agree on B ), and C B is satised (because there arent any dierent tuples that agree on C ). Yet, A C is not satised (there are two tuples that agree on A, yet they do not agree on C ). Problem 5. Consider the schema R = (A, B, C ) and the set of functional dependencies F = {A B, BC A}. 1. Use Armstrongs Axioms to generate F + ; i.e., the set of all functional dependencies that are entailed by F . Indicate on the list the functional dependencies that are trivial. Answer: Generating F + could be done by attempting to generate all the 49 possible functional dependencies (the argument for this number was given in Problem 1). Again, this can be summarized in a 7 x 7 table. In this table T means it is in F + because it is generated by the reexivity axiom (trivial), G means it is in F + because it is in the given set F ; a number means that it is in F + and a short derivation is given below the table; and means that it is not in the closure (could not be generated). ABC AB AC BC A B C ABC T 2 5 AB T T 4 6 8 2 AC T T 7 BC T 1 T A B C T T T T T T 3 T G T T T G T T

1. A B given; then augmentation by C . 2. AC BC derived in step 1; then augmentation by A. 3. AC A trivial; A B given; then transitivity. 4. AC B derived in step 3; then augmentation by A. 5. BC A given; then augmentation by BC . 6. BC A given; then augmentation by B . 7. BC A given; then augmentation by C . 8. A B given; then augmentation by A. Altogether F + include 29 functional dependencies. Note that discovering that a functional dependency is not in the closure (i.e., it is not a functional dependency) requires that all further attempts to infer additional functional dependencies fail. 2. By examining F + , nd all the superkeys and then the candidate keys of R. (Hint: Recall that K is a superkey of R i K R.) Answer: The closure includes 3 functional dependencies with ABC in the right-handside: ABC ABC , AB ABC , and AC ABC . Hence, ABC , AC and BC are 3 superkeys. The keys (i.e., the candidate keys; the superkeys without unnecessary attributes) are AC and BC . The superkey ABC is not a key, because there are strict subsets of it that are superkeys (both AB and AC ). Problem 6. Consider the relation schema R = (A, B, C, D, E ) and the set of functional dependencies F = {A BC, CD E, B D, E A}. 1. Show that (A, B, C ) and (A, D, E ) is a lossless-join decomposition of R (under F ). Answer: It is recommended here to play the attribute closure game and discover that A, E , CD and BC are all(candidate) keys) of R. We argued that a decomposition is lossless if the intersection of the schemas is a superkey of at least one of the schemas. The intersection of these two schemas is A, and A is a superkey of both schemas (obviously, since A is a superkey of ABCDE , it is a superkey of any subset of ABCDE that includes it). 2. Show that (A, B, C ) and (C, D, E ) is not a lossless-join decomposition of R (under F ). Answer: The intersection of these two schemas is C , and C is not a superkey of neither ABC nor CDE . Recall that X is a superkey of R if X R; in other words, X is a superkey of R if the attribute closure of X is R (X + = R). Yet, in the attribute closure game, clicking on C does not color red neither ABC nor CDE . 3. Using the normalization algorithm, nd a lossless-join decomposition of R (under F ) into BCNF relation schemas. Answer: 1. The given relation schema ABCDE is not in BCNF. 2. An example functional dependency that violates BCNF is B D (because it is not trivial and the left-hand-side is not a superkey). 3

3. Based on this functional dependency we decompose R into ABCE and BD. 4. Both are in BCNF and we are done. Problem 7. Consider the relation schema R = (A, B, C, D, E ), and the set of functional dependencies F = {A C, D CB, AC E }. 1. Is (A, B, C, D, E ) in BCNF (under F )? Why? Answer: Again, use the attribute closure game to discover that the only (candidate) key is AD. Consequently, ABCDE is not in BCNF, because of the functional dependency A C which is not trivial and its left-hand-side is not a superkey. 2. Is (C, D, E ) in BCNF (under F )? Why? Answer: Wiping away A and B from the game board (along with the arrows D B , A C and AC E ), leaves the game board with three boxes: C , D and E , and one connecting arrow from D to C . The (candidate) key of this schema is therefore DE . Consequently, DCE is not in BCNF, because the functional dependency D E is not trivial and its left-hand-side is not a superkey. 3. Is (A, B, C ) in BCNF (under F )? Why? Answer: Wiping away D and E from the game board (along with the arrows D C , D B , and AC E ), leaves the game board with three boxes A, C and B , and one connecting arrow from A to C . The (candidate) key of this schema is therefore AB . Consequently, ABC is not in BCNF, because the functional dependency A C is not trivial and its left-hand-side is not a superkey. 4. Is (A, B, C ) and (C, D, E ) a lossless-join decomposition (under F )? Why? Answer: The intersection of these two schemas is C , and C is not a superkey of neither ABC nor CDE (as we just showed, the candidate keys of these schemas are, respectively, AB and DE ). 5. Using the normalization algorithm, nd a lossless-join decomposition of (A, B, C, D, E ) into BCNF relation schemas (under F ). Answer: 1. The given relation schema ABCDE is not in BCNF. 2. An example functional dependency that violates BCNF is D BC (because it is not trivial and the left-hand-side is not a superkey). 3. Based on this functional dependency we decompose R into DBC and ADE . 4. BCD is in BCNF: D is its key with only two non-trivial functional dependencies: D B and D C . 5. The other schema ADE is not in BCNF yet. Why? Wiping away C and B from the game board (along with the arrows D B , A C and AC E ), leaves the game board with three boxes A, D and E , and no connecting arrows. But we must introduce the arrow A E because it is entailed from A C and AC E . The (candidate) key of this schema is therefore AD. Consequently, ADE is not in BCNF, because the functional dependency A E is not trivial and its left-hand-side is not a superkey. 4

6. Based on the functional dependency A D we decompose ADE into AD and AE . 7. The nal design is DBC , AD, AE . Problem 8. Consider a database for surgery appointments. The patient is given an appointment at a specic time and date and at a particular surgery location. On each date for which there are appointments, one surgeon is assigned to a specic surgery location for that entire day. Initially, the following relation schema is proposed: R = (SurgId, SurgN ame, P atId, P atN ame, AppDate, AppT ime, SurgLoc), where SurgId is surgeon identication number, SurgName is surgeon name, PatId is patient identication number, PatNameia is patient name, AppDate is appointment date, AppTime is appointment time, and is surgery location. 1. List the functional dependencies that denote the information given above. Answer: We abbreviate the attributes, respectively, with Sid, Sname, Pid, Pname, Date, Time, Loc. 1. Sid Sname (obvious) 2. P id P name (obvious) 3. Date, Loc Sid (on given date, a location is assigned one surgeon) 4. Date, Sid Loc (on given date, a surgeon is assigned to one location) 5. Date, T ime, P id Loc (on given date and time, a patient is in one location) 6. Date, T ime, Loc P id (on given date and time, a location has one patient) 7. Date, T ime, Sid P id (on given date and time, a surgeon is with one patient) 8. Date, T ime, P id Sid (on given date and time, a patient is with one surgeon) The pair 3 and 4 can be summarized: On given date, location and surgeon are one-toone. The pair 5 and 6 can be summarized: On given date and time, location and patient are one-to-one. The pair 7 and 8 can be summarized: On given date and time, surgeon and patient are one-to-one. It can be shown that 7 and 8 are entailed from 36. The (candidate) keys of the schema are: 1. Date, T ime, P id 2. Date, T ime, Sid 3. Date, T ime, Loc In other words, an apppointment can be identied uniquely by specifying the date and time and either the patient or the surgeon or the location. 2. Describe the negative aspects of the initial relation.

Answer: There are multiple anomalies including (there are others as well!) 1. The surgeon name is repeated in all appointments with the same surgeon. 2. The patient name is repeated in all appointments with the same patient. 3. The location is repeated in all appointments on the same date and with the same surgeon. 4. The surgeon id is repeated in all appointments on the same date and in the same location. 3. Using the normalization algorithm, nd a lossless-join decomposition of R into BCNF relations schemas (under the set of functional dependencies listed earlier). Answer: 1. Initial design: R0 = (P id, P name, Sid, Sname, Date, T ime, Loc) R0 is not in BCNF. Choose the functional dependency P id P name and replace R0 with R1 = (P id, P name) R2 = (P id, Sid, Sname, Date, T ime, Loc) 2. Current design: R1 , R2 . R1 is in BCNF but R2 is not. Choose the functional dependency Sid Sname and replace R2 with R3 = (Sid, Sname) R4 = (P id, Sid, Date, T ime, Loc) 3. Current design: R1 , R3 , R4 . R1 and R3 are in BCNF but R4 is not. Choose Loc, Date Sid and replace R4 with R5 = (Date, Sid, Loc) S6 = (Date, T ime, P id, Sid) 4. Current design: R1 , R3 , R5 , R6 . All schemas are in BCNF. Done. Intuitively, R1 and R3 are, respectively, the patient le and the surgeon le. R5 is the assignment of surgeons to locations, and R6 is the appointment le. Alternatively, in Step 3 we could choose Sid, Date Loc, and replace R4 with the same assignment le R5 , but with the appointment le R6 = (Date, T ime, P id, Loc).

You might also like