0% found this document useful (0 votes)
110 views7 pages

Norm Ans

This document contains exercises about schema refinement and normal forms in database design. It includes questions about defining functional dependencies, determining when relations satisfy different normal forms like 1NF, 2NF, 3NF and BCNF, and decomposing relations into BCNF when necessary to eliminate anomalies. Sample solutions are provided that analyze relations and their dependencies to identify candidate keys, applicable normal forms, and BCNF decompositions when needed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views7 pages

Norm Ans

This document contains exercises about schema refinement and normal forms in database design. It includes questions about defining functional dependencies, determining when relations satisfy different normal forms like 1NF, 2NF, 3NF and BCNF, and decomposing relations into BCNF when necessary to eliminate anomalies. Sample solutions are provided that analyze relations and their dependencies to identify candidate keys, applicable normal forms, and BCNF decompositions when needed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

19

SCHEMA REFINEMENT AND


NORMAL FORMS

Exercise 19.1 Briefly answer the following questions:

1. Define the term functional dependency.


2. Why are some functional dependencies called trivial?
3. Give a set of FDs for the relation schema R(A,B,C,D) with primary key AB under
which R is in 1NF but not in 2NF.
4. Give a set of FDs for the relation schema R(A,B,C,D) with primary key AB under
which R is in 2NF but not in 3NF.
5. Consider the relation schema R(A,B,C), which has the FD B → C. If A is a can-
didate key for R, is it possible for R to be in BCNF? If so, under what conditions?
If not, explain why not.
6. Suppose we have a relation schema R(A,B,C) representing a relationship between
two entity sets with keys A and B, respectively, and suppose that R has (among
others) the FDs A → B and B → A. Explain what such a pair of dependencies
means (i.e., what they imply about the relationship that the relation models).
Answer 19.1
1. Let R be a relational schema and let X and Y be two subsets of the set of all
attributes of R. We say Y is functionally dependent on X, written X → Y, if the
Y-values are determined by the X-values. More precisely, for any two tuples r1
and r2 in (any instance of) R
πX (r1 ) = πX (r2 ) ⇒ πY (r1 ) = πY (r2 )

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

3. Consider the set of FD: AB → CD and B → C. AB is obviously a key for this


relation since AB → CD implies AB → ABCD. It is a primary key since there are
no smaller subsets of keys that hold over R(A,B,C,D). The FD: B → C violates
2NF since:
C ∈ B is false; that is, it is not a trivial FD
B is not a superkey
C is not part of some key for R
B is a proper subset of the key AB (transitive dependency)

4. Consider the set of FD: AB → CD and C → D. AB is obviously a key for this


relation since AB → CD implies AB → ABCD. It is a primary key since there are
no smaller subsets of keys that hold over R(A,B,C,D). The FD: C → D violates
3NF but not 2NF since:
D ∈ C is false; that is, it is not a trivial FD
C is not a superkey
D is not part of some key for R

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.

1. List all keys for R.

2. Is R in 3NF?

3. Is R in BCNF?

Answer 19.2

1. CDE, ACD, BCD

2. R is in 3NF because B, E and A are all parts of keys.

3. R is not in BCNF because none of A, BC and ED contain a key.

Exercise 19.3 Consider the relation shown in Figure 19.1.

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

Figure 19.1 Relation for Exercise 19.3.

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

1. The following functional dependencies hold over R: Z → Y, X → Y, and XZ → Y

2. Same as part 1. Functional dependency set is unchanged.

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.

Answer 19.4 Assuming...

1. The following statement returns 0 iff no statement violates the FD A → B.

SELECT COUNT (*)


FROM R AS R1, R AS R2
WHERE (R1.B != R2.B) AND (R1.A = R2.A)

2. CREATE ASSERTION ADeterminesB


CHECK ((SELECT COUNT (*)
FROM R AS R1, R AS R2
WHERE (R1.B != R2.B) AND (R1.A = R2.A))
=0)
Schema Refinement and Normal Forms 261

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.

SELECT COUNT (*)


FROM R AS R1, R AS R2
WHERE ((R1.B != R2.B) AND (R1.A = R2.A))
OR ((R1.B is NULL) AND (R2.B is NOT NULL)
AND (R1.A = R2.A))

CREATE ASSERTION ADeterminesBNull


CHECK ((SELECT COUNT (*)
FROM R AS R1, R AS R2
WHERE ((R1.B != R2.B) AND (R1.A = R2.A)))
OR ((R1.B is NULL) AND (R2.B is NOT NULL)
AND (R1.A = R2.A))
=0)

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

1. 1NF. BCNF decomposition: AB, CD, ACE.

2. 1NF. BCNF decomposition: AB, BF

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?

(a) A → B, (b) BC → A, (c) B → C

2. Can you identify any dependencies that hold over 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

1. (a) Candidate keys: B


(b) R is in 2NF but not 3NF.
(c) C → D and C → A both cause violations of BCNF. One way to obtain a
(lossless) join preserving decomposition is to decompose R into AC, BC, and
CD.

2. (a) Candidate keys: BD


(b) R is in 1NF but not 2NF.
Schema Refinement and Normal Forms 263

(c) Both B → C and D → A cause BCNF violations. The decomposition: AD,


BC, BD (obtained by first decomposing to AD, BCD) is BCNF and lossless
and join-preserving.

3. (a) Candidate keys: ABC, BCD


(b) R is in 3NF but not BCNF.
(c) ABCD is not in BCNF since D → A and D is not a key. However if we split
up R as AD, BCD we cannot preserve the dependency ABC → D. So there
is no BCNF decomposition.

4. (a) Candidate keys: A


(b) R is in 2NF but not 3NF (because of the FD: BC → D).
(c) BC → D violates BCNF since BC does not contain a key. So we split up R
as in: BCD, ABC.

5. (a) Candidate keys: AB, BC, CD, AD


(b) R is in 3NF but not BCNF (because of the FD: C → A).
(c) C → A and D → B both cause violations. So decompose into: AC, BCD
but this does not preserve AB → C and AB → D, and BCD is still not
BCNF because D → B. So we need to decompose further into: AC, BD,
CD. However, when we attempt to revive the lost functioanl dependencies
by adding ABC and ABD, we that these relations are not in BCNF form.
Therefore, there is no BCNF decomposition.

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

2. Which of the following decompositions of R = ABCDEG, with the same set of


dependencies F , is (a) dependency-preserving? (b) lossless-join?

(a) {AB, BC, ABDE, EG }


(b) {ABC, ACDE, ADG }

Answer 19.8

1. (a) i. R1 = ABC: The FD’s are AB → C, AC → B, BC → A.


264 Chapter 19

ii. This is already a minimal cover.


iii. This is in BCNF since AB, AC and BC are candidate keys for R1. (In
fact, these are all the candidate keys for R1).
(b) i. R2 = ABCD: The FD’s are AB → C, AC → B, B → D, BC → A.
ii. This is a minimal cover already.
iii. The keys are: AB, AC, BC. R2 is not in BCNF or even 2NF because of
the FD, B → D (B is a proper subset of a key!) However, it is in 1NF.
Decompose as in: ABC, BD. This is a BCNF decomposition.
(c) i. R3 = ABCEG; The FDs are AB → C, AC → B, BC → A, E → G.
ii. This is in minimal cover already.
iii. The keys are: ABE, ACE, BCE. It is not even in 2NF since E is a proper
subset of the keys and there is a FD E → G. It is in 1NF . Decompose
as in: ABE, ABC, EG. This is a BCNF decompostion.
(d) i. R4 = DCEGH; The FD is E → G.
ii. This is in minimal cover already.
iii. The key is DCEH ; It is not in BCNF since in the FD E → G, E is a
subset of the key and is not in 2NF either. It is in 1 NF Decompose as
in: DCEH, EG
(e) i. R5 = ACEH; No FDs exist.
ii. This is a minimal cover.
iii. Key is ACEH itself.
iv. It is in BCNF form.

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.

This decomposition does not preserve the FD, AB → C (or AC → B)


(b) The decomposition {ABC, ACDE, ADG } is lossless. Intuitively, this is
because the join of ABC, ACDE and ADG can be constructed in two steps;
first construct the join of ABC and ACDE: this is lossless because their
(attribute) intersection is AC which is a key for ABCDE (in fact ABCDEG)
so this is lossless. Now join this intermediate join with ADG. This is also
lossless because the attribute intersection is is AD and AD → ADG. So by
the test mentioned in the text this step is also a lossless decomposition.

You might also like