Relational Database Design: Exercises
Relational Database Design: Exercises
8
Relational Database Design
This chapter presents the principles of relational database design. Undergradu-
ates frequently find this chapter difficult. It is acceptable to cover only Sections 8.1
and 8.3 for classes that find the material particularly difficult. However, a care-
ful study of data dependencies and normalization is a good way to introduce
students to the formal aspects of relational database theory.
There are many ways of stating the definitions of the normal forms. We have
chosen a style which we think is the easiest to present and which most clearly
conveys the intuition of the normal forms.
Exercises
and yet, isbn is not a super key. Thus, we break books into
isbn →→ author
but neither is isbn a primary key of book details, nor are the attributes of
book details equal to {isbn} ∪ {author}. Therefore we decompose book details
again into
Similarly, in users,
deptid → deptname
8.23 Why are certain functional dependencies called trivial functional depen-
dencies?
Answer: Certain functional dependencies are called trivial functional
dependencies because they are satisfied by all relations.
8.24 Use the definition of functional dependency to argue that each of Arm-
strong’s axioms (reflexivity, augmentation, and transitivity) is sound.
Answer: The definition of functional dependency is: a → b holds on R
if in any legal relation r (R), for all pairs of tuples t1 and t2 in r such that
t1 [a] = t2 [a], it is also the case that t1 [b] = t2 [b].
70 Chapter 8 Relational Database Design
t1 [g ] = t2 [g ] g ⊆ ga
t1 [a] = t2 [a] a ⊆ ga
t1 [b] = t2 [b] definition of a → b
t1 [g b] = t2 [g b] gb = g ∪ b
ga → gb definition of FD
Transitivity rule: if a → b and b → g , then a → g .
Assume ∃ t1 , t2 such that t1 [a] = t2 [a]
a → bg given
bg → b reflexivity rule
a → b transitivity rule
bg → g reflexive rule
a → g transitive rule
8.27 Using the functional dependencies of Practice Exercise 8.6, compute B + .
Exercises 71
(A, B, C)
(C, D, E).
5 A, B, C (r ) 1 5C, D, E (r ) 6= r
A B C D E
a1 b1 c1 d1 e1
a2 b2 c1 d2 e2
With R1 = (A, B, C), R2 = (C, D, E) :
a. 5 R1 (r ) would be:
A B C
a1 b1 c1
a2 b2 c1
b. 5 R2 (r ) would be:
C D E
c1 d1 e1
c1 d2 e2
c. 5 R1 (r ) 1 5 R2 (r ) would be:
A B C D E
a1 b1 c1 d1 e1
a1 b1 c1 d2 e2
a2 b2 c1 d1 e1
a2 b2 c1 d2 e2
A → BCD
BC → DE
B→D
D→A
a. Compute B + .
b. Prove (using Armstrong’s axioms) that AF is a superkey.
c. Compute a canonical cover for the above set of functional depen-
dencies F ; give each step of your derivation with an explanation.
d. Give a 3NF decomposition of r based on the canonical cover.
e. Give a BCNF decomposition of r using the original set of functional
dependencies.
f. Can you get the same BCNF decomposition of r as above, using the
canonical cover?
Answer:
a. B → BD (third dependency)
BD → ABD (fourth dependency)
ABD → ABCD (first dependency)
ABCD → ABCDE (second dependency)
+
Thus, B = ABCDE
b. Prove (using Armstrong’s axioms) that AF is a superkey.
A → BCD (Given)
A → ABCD (Augmentation with A)
BC → DE (Given)
ABCD → ABCDE (Augmentation with ABCD)
A → ABCDE (Transitivity)
AF → ABCDEF (Augmentation with F)
e. We start with
r(A, B, C, D, E, F)
We see that the relation is not in BCNF because of the first FD. Hence,
we decompose it accordingly to get
r1 (A, B, C, D) r2 (A, E, F)
Now we notice that A → E is an FD in F + , and causes r2 to violate
BCNF. Once again, decomposing r2 gives
• Repetition of information
• Inability to represent information
• Loss of information.
2NF does not prohibit as much repetition of information since the schema
(A, B, C) with dependencies A → B and B → C is allowed under 2NF,
although the same (B, C) pair could be associated with many A values,
needlessly duplicating C values. To avoid this we must go to 3NF. Repetition
of information is allowed in 3NF in some but not all of the cases where it
is allowed in 2NF. Thus, in general, 3NF reduces repetition of information.
Since we can always achieve a lossless join 3NF decomposition, there is no
loss of information needed in going from 2NF to 3NF.
Note that the decomposition {(A, B), (B, C)} is a dependency-preserving
and lossless-loin 3NF decomposition of the schema (A, B, C). However,
in case we choose this decomposition, retrieving information about the
relationship between A, B and C requires a join of two relations, which is
avoided in the corresponding 2NF decomposition.
Thus, the decision of which normal form to choose depends upon how the
cost of dependency checking compares with the cost of the joins. Usually,
the 3NF would be preferred. Dependency checks need to be made with
every insert or update to the instances of a 2NF schema, whereas, only some
queries will require the join of instances of a 3NF schema.
8.33 Given a relational schema r (A, B, C, D), does A →→ BC logically imply
A →→ B and A →→ C? If yes prove it, else give a counter example.
Answer: A →→ BC holds on the following table:
Exercises 75
r: A B C D
a1 b1 c1 d1
a1 b2 c2 d2
a1 b1 c1 d2
a1 b2 c2 d1
If A →→ B, then we know that there exists t1 and t3 such that t1 [B] = t3 [B].
Thus, we must choose one of the following for t1 and t3 :
• t1 = r1 and t3 = r3 , or t1 = r3 and t3 = r1 :
Choosing either t2 = r2 or t2 = r4 , t3 [C] 6= t2 [C].
• t1 = r2 and t3 = r4 , or t1 = r4 and t3 = r2 :
Choosing either t2 = r1 or t2 = r3 , t3 [C] 6= t2 [C].
Therefore, the condition t3 [C] = t2 [C] can not be satisfied, so the conjecture
is false.
8.34 Explain why 4NF is a normal form more desirable than BCNF.
Answer: 4NF is more desirable than BCNF because it reduces the repeti-
tion of information. If we consider a BCNF schema not in 4NF (see Practice
Exercise 7.16), we observe that decomposition into 4NF does not lose infor-
mation provided that a lossless join decomposition is used, yet redundancy
is reduced.