Norm Ans
Norm Ans
2. Some functional dependencies are considered trivial because they contain super-
fluous attributes that do not need to be listed. Consider the FD: A → AB. By
reflexivity, A always implies A, so that the A on the right hand side is not neces-
sary and can be dropped. The proper form, without the trivial dependency would
then be A → B.
258
Schema Refinement and Normal Forms 259
5. The only way R could be in BCNF is if B includes a key, i.e. B is a key for R.
6. It means that the relationship is one to one. That is, each A entity corresponds
to at most one B entity and vice-versa. (In addition, we have the dependency AB
→ C, from the semantics of a relationship set.)
Exercise 19.2 Consider a relation R with five attributes ABCDE. You are given the
following dependencies: A → B, BC → E, and ED → A.
2. Is R in 3NF?
3. Is R in BCNF?
Answer 19.2
1. List all the functional dependencies that this relation instance satisfies.
260 Chapter 19
X Y Z
x1 y1 z1
x1 y1 z2
x2 y1 z1
x2 y1 z3
2. Assume that the value of attribute Z of the last record in the relation is changed
from z3 to z2 . Now list all the functional dependencies that this relation instance
satisfies.
Answer 19.3
Exercise 19.4 Assume that you are given a relation with attributes ABCD.
1. Assume that no record has NULL values. Write an SQL query that checks whether
the functional dependency A → B holds.
2. Assume again that no record has NULL values. Write an SQL assertion that
enforces the functional dependency A → B.
3. Let us now assume that records could have NULL values. Repeat the previous
two questions under this assumption.
3. Note that the following queries can be written with the NULL and NOT NULL
interchanged. Since we are doing a full join of a table and itself, we are creating
tuples in sets of two therefore the order is not important.
Exercise 19.5 Consider the following collection of relations and dependencies. As-
sume that each relation is obtained through decomposition from a relation with at-
tributes ABCDEFGHI and that all the known dependencies over relation ABCDEFGHI
are listed for each question. (The questions are independent of each other, obviously,
since the given dependencies over ABCDEFGHI are different.) For each (sub)relation:
(a) State the strongest normal form that the relation is in. (b) If it is not in BCNF,
decompose it into a collection of BCNF relations.
1. R1(A,C,B,D,E), A → B, C → D
2. R2(A,B,F), AC → E, B → F
3. R3(A,D), D → G, G → H
4. R4(D,C,H,G), A → I, I → A
5. R5(A,I,C,E)
Answer 19.5
3. BCNF.
4. BCNF.
5. BCNF.
262 Chapter 19
Exercise 19.6 Suppose that we have the following three tuples in a legal instance of
a relation schema S with three attributes ABC (listed in order): (1,2,3), (4,2,3), and
(5,3,3).
1. Which of the following dependencies can you infer does not hold over schema S?
Answer 19.6
1. BC→ A does not hold over S (look at the tuples (1,2,3) and (4,2,3)). The other
tuples hold over S.
2. No. Given just an instance of S, we can say that certain dependencies (e.g., A →
B and B → C) are not violated by this instance, but we cannot say that these
dependencies hold with respect to S. To say that an FD holds w.r.t. a relation is
to make a statement about all allowable instances of that relation!
Exercise 19.7 Suppose you are given a relation R with four attributes ABCD. For
each of the following sets of FDs, assuming those are the only dependencies that hold
for R, do the following: (a) Identify the candidate key(s) for R. (b) Identify the best
normal form that R satisfies (1NF, 2NF, 3NF, or BCNF). (c) If R is not in BCNF,
decompose it into a set of BCNF relations that preserve the dependencies.
1. C → D, C → A, B → C
2. B → C, D → A
3. ABC → D, D → A
4. A → B, BC → D, A → C
5. AB → C, AB → D, C → A, D → B
Answer 19.7
Exercise 19.8 Consider the attribute set R = ABCDEGH and the FD set F = {AB →
C, AC → B, AD → E, B → D, BC → A, E → G}.
1. For each of the following attribute sets, do the following: (i) Compute the set of
dependencies that hold over the set and write down a minimal cover. (ii) Name
the strongest normal form that is not violated by the relation containing these
attributes. (iii) Decompose it into a collection of BCNF relations if it is not in
BCNF.
(a) ABC, (b) ABCD, (c) ABCEG, (d) DCEGH, (e) ACEH
Answer 19.8
2. (a) The decomposition. { AB, BC, ABDE, EG } is not lossless. To prove this
consider the following instance of R:
{(a1 , b, c1 , d1 , e1 , g1 ), (a2 , b, c2 , d2 , e2 , g2 )}
Because of the functional dependencies BC → A and AB → C, a1 = a2 if
and only if c1 = c2 . It is easy to that the join AB BC contains 4 tuples:
{(a1 , b, c1 ), (a1 , b, c2 ), (a2 , b, c1 ), (a2 , b, c2 )}
So the join of AB, BC, ABDE and EG will contain at least 4 tuples, (actually
it contains 8 tuples) so we have a lossy decomposition here.