Exercises of April 27, 2006
1
CHAPTER 11: RELATIONAL DATABASE DESIGN ALGORITHMS AND FURTHER DEPENDENCIES
Answers to Selected Exercises 11.15 Show that the relation schemas produced by Algorithm 11.2 are in 3NF. Answer: We give a proof by contradiction. Suppose that one of the relations Ri resulting from Algorithm 11.2 is not in 3NF. Then (by definition of 3 NF) a FD Y > A holds in Ri where: (a) Y is not a superkey of Ri, and (b) A is not a prime attribute. According to step 2 of the algorithm, Ri will contain a set of attributes X ∪ A 1 ∪ ... ∪ An, X is a key of Ri and the A i are the nonprime attributes of Ri. The set G of FD’s X > Ai is minimal. Hence, if an FD Y > A holds in Ri where A is nonprime and Y is not a superkey of Ri , Y must be a proper subset of X (otherwise Y would contain X and hence be a superkey, and Y cannot contain nonprime attributes). If both Y > A and X > A hold and Y is a proper subset of X, this contradicts that X > A is a FD in a minimal set of FDs that is input to the algorithm, since removing an attribute from X leaves a valid FD, thus violating one of the minimality conditions. This produces a contradiction of our assumptions. Hence, Ri must be in 3NF.
This material has been taken from draft PrePublication Material, Copyright AWL2004
which will be a spurious tuple (since it did not exist in S but will exist after projecting and joining over the Ri's). Answer: The matrix S initially has one row for each relation Ri in the decomposition. but with different values for the A and C attributes.C) without any FD’s and its decomposition R1(A. 2006
11. Brand) and R2(Brand. with the same value for the B attribute. take R(A. If this line of reasoning is not immediate clear.e. a2) and S(R2) = (a2. for S(R1) Bar Hardrock Cooldown Brand Heineken Heineken
and for S(R2) Brand Heineken Heineken Beer Amstel1870 Pilsener
Joining these projections will give us
This material has been taken from draft PrePublication Material. S does not have a row that is all "a". If we take the two projections. To instantiate this example even more. that corresponds with the initial value of the matrix S.1 does not have a row that is all "a" symbols. with "a" symbols under the columns for the attributes in Ri. as there are no FD’s at all. Let us take an extension of R (a concrete set of tuples). if after applying the algorithm.C). a2. Hence.16 Show that if the matrix S resulting from Algorithm 11. Copyright AWL2004
. Then the initial matrix S will be R1 R2 A a1 b21 B C a2 b12 a 2 a3
The algorithm will stop immediate. a3) and join these results we get a spurious tuple (a1. take R(Bar. a tuple which did not exist in the set of tuples from which we started. Joining these back together again will produce at least one row of all "a" symbols (resulting from joining the all "a" rows in each projection S(Ri)). a3). Brand. projecting S on each Ri at the end of applying the algorithm will produce one row consisting of all "a" symbols in each S(Ri).B) and R2(B. Beer). So we have two tuples. then projecting S on the decomposition and joining it back will always produce at least one spurious tuple. and the following extension Bar Hardrock Cooldown Brand Heineken Heineken Beer Amstel1870 Pilsener
The two projections will contain. S(R1) = (a1.2
Exercises of April 27. Beer) with R1(Bar.. projecting S over the Ri's and joining will result in at least one all "a" row. i. Since we never change an "a" symbol into a "b" symbol during the application of the algorithm.B.
but not both. In the Beerexample this means that the Brand (i.e. a2.C) case. 2006
3
Bar Hardrock Hardrock Cooldown Cooldown
Brand Heineken Heineken Heineken Heineken
Beer Amstel1870 Pilsener Amstel1870 Pilsener
We see two spurious tuples. Note that if return to the R(A.Exercises of April 27. Heineken) must determine the Beer which must be either Amstel1870 or Pilsener. one of them is (Hardrock. then we obtain the matrix R1 R2 A a1 b21 B C a 2 a3 a 2 a3
Which shows us that in this case the lossless join property does hold. we add the FD B > C and we apply the algorithm again.B. Heineken. Copyright AWL2004
. a3). Pilsener).
This material has been taken from draft PrePublication Material. corresponding with the spurious tuple (a1.
y.
This material has been taken from draft PrePublication Material. so does the condition for multivalued dependency. Then. whenever the condition for functional dependency holds. t3[Y]= t2[Y]. we must have two tuples t3 and t4 (not necessarily distinct from t1 and t2 ) satisfying: • • • • • t3[X]= t4[X]= t1[X]= t2[X].4
Exercises of April 27. t3[Z]= t1[Z]. Suppose the tuples are t1 = < x. they must also have the same value of Y. Hence. z1 > and t2 = < x. Copyright AWL2004
. Z}. z2 >. according to the definition of multivalued dependency. t4[Y]= t1[Y]. y. Because of the functional dependency.
Two tuples satisfying this are t2 (satisfies conditions for t4 ) and t1 (satisfies conditions for t3). Y.21 Prove that a functional dependency is also a multivalued dependency. Answer: Suppose that a functional dependency X > Y exists in a relation R={X. and suppose there are two tuples with the same value of X. and t4[Z]= t2[Z]. 2006
11.
E. and (iii) determine which normal form the decomposition is in. with all a’s in the R1 row.e. so this decomposition is in BCNF. {B} > {F}.H}.G.H}. • Does the lossless join property hold? We start with the following matrix: R1 R2 R3 R4 R5 A a1 a1 b31 b41 b51 B a2 b22 a2 b42 b52 C a3 b23 b33 b43 b53 D b14 a4 b34 b44 a4 E b15 a5 b35 b45 b55 F b16 b26 a6 a6 b56 G b17 b27 b37 a7 b57 H b18 b28 b38 a8 b58 I b19 b29 b39 b49 a9 J b110 b210 b310 b410 a10
We apply the Fd’s as follows: . (ii) the lossless join property holds.D.C}. which are also MVD’s/FD’s.E}. • All dependencies are preserved. R3 = {D.J}. no changes.Exercises of April 27. R2 = {A. Hence. no changes.E}. R3}. there are only join dependencies.C. R2.I. a9 and a10 are copied from R5 to R1 and R2 This gives us the following matrix.G.
This material has been taken from draft PrePublication Material.H}.B. R2 = {B. this decomposition does satisfy the lossless join property.
b) D2 = {R1.{F} > {G.{D}> {I. R5}.I.J}. i. For every FD X > A in F It holds that X is the key of the associated (sub)relation scheme. There are no real MVD’s.E}.{B} > {F}. R3 = {B. a7 and a8 are copied from R4 to R1 and R3.F. {F} > {G.. • All dependencies are preserved.D. {A} > {D. a4 and a5 are copied from R2 to R1.H. Similarly.C.I. . • Does the lossless join property hold? We start with the following matrix: R1 R2 R3 A a1 b21 b31 B a2 a2 b32 C a3 b23 b33 D E a4 a5 b24 b25 a4 b35 F b16 a6 b36 G b17 a7 b37 H b18 a8 b38 I b19 b29 a9 J b110 b210 a10
We apply the Fd’s as follows: {A.H}. Copyright AWL2004
. {D}> {I. R5 = {D. hence the decomposition is also in 5 NF. .{A.J}. 2006
5
11.B.B} > C. a6 is copied from R3 to R1.B. Determine for each of the following decompositions whether (i) the dependencies are preserved. R1 R2 R3 R4 R5 • A a1 a1 b31 b41 b51 B a2 b22 a2 b42 b52 C a3 b23 b33 b43 b53 D a4 a4 b34 b44 a4 E a5 a5 b35 b45 b55 F a6 b26 a6 a6 b56 G a7 b27 a7 a7 b57 H a8 b28 a8 a8 b58 I a9 a9 b39 b49 a9 J a10 a10 b310 b410 a10
There are no partial dependencies. every MVD is also an FD. JD’s. .E}. R1 = {A. R4 = {F. R2.F}.29 Consider universal relation R(A.E}. so it is at least in 2 NF.D.J}}. R3. {A} > {D. no changes.B} > C.B} > C.{A} > {D.J) of Exercise 10:26 with the following set of FD’s F = {{A. a) D1 = {R1. hence the decomposition is also in 4 NF. R4. R1 = {A.G.F. .
{A. a7 and a8 are copied from R2 to R1. R3 = {B.B} > C.G.
c) D3 = {R1.6
Exercises of April 27. R4 = {F. no changes. Hence.I. R5}. .{D}> {I.
This material has been taken from draft PrePublication Material. R2.C. a9 and a10 are copied from R3 to R1. with all a’s in the R1 row.{F} > {G.H}. • Does the lossless join property hold? We start with the following matrix: R1 R2 R3 R4 R5 A a1 b12 b31 b41 b51 B a2 b22 a2 b42 b52 C a3 b23 b33 b43 b53 D a4 a4 b34 b44 a4 E b15 a5 b35 b45 b55 F b16 b26 a6 a6 b56 G b17 b27 b37 a7 b57 H b18 b28 b38 a8 b58 I b19 b29 b39 b49 a9 J b110 b210 b310 b410 a10
We apply the Fd’s as follows: . • The dependency A > E is not preserved. the lossless join property does not hold. this decomposition does satisfy the lossless join property. R1 = {A. no changes. Hence.J}. hence it is in 1 NF. because of the partial dependency {A} > {D. .E}. R1 R2 R3 • A a1 b21 b31 B a2 a2 b32 C a3 b23 b33 D E a4 a5 b24 b25 a4 b35 F a6 a6 b36 G a7 a7 b37 H a8 a8 b38 I a9 b29 a9 J a10 b210 a10
It is in 1 NF. R2 = {D.E}. R5 = {D. a6 is copied from R2 to R1.{B} > {F}. . Note that we would need an FD {D} > {E} to change the b15 field in the R1 into a5.B.D}.{A} > {D. .J}. Iterating over this loop will not give us any new updates. a7 and a8 are copied from R4 to R1 and R3. R3. {F} > {G.E}.
This gives us the following matrix.H}. so we stop with all rows containg at least one “b”. R1 R2 R3 R4 R5 • A a1 b12 b31 b41 b51 B a2 b22 a2 b42 b52 C a3 b23 b33 b43 b53 D a4 a4 b34 b44 a4 E b15 a5 b35 b45 b55 F a6 b26 a6 a6 b56 G a7 b27 a7 a7 b57 H a8 b28 a8 a8 b58 I a9 a9 b39 b49 a9 J a10 a10 b310 b410 a10
Because of the partial dependency {A} > {D} it cannot be in 2 NF.J}. a9 and a10 are copied from R5 to R1 and R2.H}. R4.F}. Copyright AWL2004
. 2006

{B} > {F}. a6 is copied from R3 to R1. {D}> {I.
C} R1 = {M. and the following set of F of functional dependencies: F={M > MP. The FD {M} > {MP} is in F. Alternatively: BCNF can be directly tested by using all of the given dependencies and finding out if the left hand side of each is a superkey (or if the right hand side is a prime attribute). P. giving proper reasons.MP. {M. {M. P.4) Answers: (a) • • • {M} IS NOT a candidate key since it does not functionally determine attributes Y or P. P}.Y} > P.Y} is the key which makes M > MP a partial dependency. 2006
7
11.1. {M. C} F = { M > MP. Y.Y}. By transitivity (M > MP and MP > C) we also know that M > C.
(b) REFRIG is not in 2NF.C)}. {M.Exercises of April 27. because {M. {M. MP. C} IS NOT a candidate key since it does not functionally determine attributes Y or P. Since neither M nor MP is a superkey. MP > C} (a) Evaluate each of the following as a candidate key for REFRIG.
This material has been taken from draft PrePublication Material.C} (b) Based on the above key determination. (c) Consider the decomposition of REFRIG into D={R1(M. state whether the relation REFRIG is in 3NF and in BCNF. MP. C). R1 R2 > R2 – R1 is in F+ by which we have shown the lossless property. COLOR). Y. C}. and the FD {M} > {C} is in F+ by transitivity of M > MP and MP > C. {M. Therefore REFRIG is neither in 3NF nor in BCNF. we can conclude that REFRIG is is neither in 3NF nor in BCNF. MP. Take the two FD’s M > MP and MP > C.Y. Copyright AWL2004
. R2 = {M.Y} > P.30 Consider the relation REFRIG(MODEL#. and C. Y. Y} IS a candidate key since it functionally determines the remaining attributes P. which is abbreviated as REFRIG(M. Is this decomposition lossless? Show why. YEAR. From F it is immediate the MP and P are functionally determined by M and Y. R2 (M. C} R1 R2 > R2 – R1 (see Property LJ1) reduces to {M} > {MP. (You may consult the test under Property LJ1 in Section 11. PRICE. (c) R = {M. MANUF_PLANT.P). MP > C} R1 R2 = {M} R2 – R1 = {MP. giving reasons why it can or cannot be a key: {M}. Hence. MP.