Lab 2
Functional dependencies and Normal forms
EXERCISES
1. Consider the relation scheme with attributes S (store), D (department), I (item), and
M (manager), with functional dependencies SI D and SD M.
a) Find all keys for SDIM.
b) Show that SDIM is in second normal form but not third normal form.
SOLUTION:
a) The key is SI. This is because the combination of Store (S) and Item (I) can
determine all other attributes in the relation (Department (D) and Manager (M)).
b) The relation is in Second Normal Form (2NF) because every non-prime attribute (D
and M) is fully functionally dependent on the key (SI). However, it’s not in Third
Normal Form (3NF) because there’s a transitive dependency: Manager (M) depends on
Department (D), which in turn depends on the key (SI).
2. Consider the relation scheme with attributes CITY, ST, and ZIP, which we here
abbreviate C, S, and Z. We observed the dependencies CS Z and Z C. The
decomposition of the relation scheme CSZ into SZ and CZ has a lossless join. Does
this decomposition preserve dependencies?
SOLUTION:
The original dependencies are CS → Z and Z → C.
In the decomposed relations, we have:
SZ: This relation preserves the dependency CS → Z because S is included in this
relation.
CZ: This relation preserves the dependency Z → C because both Z and C are
included in this relation.
So, all original dependencies are preserved in the decomposed relations. Therefore, the
decomposition is dependency preserving.
3. Let F = {AB C, A D, BD C}.
a) Find a minimal basis for F.
b) Give a 3NF, dependency-preserving decomposition of ABCD into only two
schemes (with respect to the set of functional dependencies F).
c) What are the projected dependencies for each of your schemes?
d) Does your answer to (b) have a lossless join? If not, how could you modify the
database scheme to have a lossless join and still preserve dependencies?
SOLUTION:
a) A minimal basis for F can be found by applying the process of attribute closure. The
minimal basis for F = {AB → C, A → D, BD → C} is {A → B, A → D, B → C}.
b) A 3NF, dependency-preserving decomposition of ABCD into only two schemes with
respect to the set of functional dependencies F can be {ABD, BC}.
c) The projected dependencies for each of your schemes are:
For ABD: {A → D}
For BC: {B → C}
d) Yes, the answer to (b) does have a lossless join. This is because the common attribute B
in both relations (ABD and BC) forms a key in one of the relations (BC). Therefore, we
don’t need to modify the database scheme to have a lossless join and still preserve
dependencies.
4. Let F = {AB C, A B}.
a) Find a minimal basis for F.
b) When (a) was given on an exam at a large western university, more than half
the class answered G = {A B, B C}. Show that answer is wrong by giving a
relation that satisfies F but violates G.
SOLUTION:
a) A minimal basis for F = {AB → C, A → B} is the same as F because each functional
dependency in F has a single attribute on the right side and the left side does not have any
extraneous attributes.
b) The answer G = {A → B, B → C} is incorrect because it is not equivalent to F. To
illustrate this, consider a relation that satisfies F but violates G:
A B C
1 2 3
1 4 5
In this relation, for the same A value (1), we have different B values (2 and 4), which
satisfies the functional dependency A → B in F. However, it violates the functional
dependency A → B in G because for the same A value, we have different B values.
Therefore, G is not a correct minimal basis for F.
5. Suppose we are given relation scheme ABCD with functional dependencies
{(A B, B C, A D, D C}. Let be the decomposition (AB, AC, BD).
a) Find the projected dependencies for each of the relation schemes of .
b) Does preserve the given dependencies?
SOLUTION:
a) The projected dependencies for each of the relation schemes of ρ are:
AB: {A → B}
AC: {A → C}
BD: {D → C}
b) Yes, ρ does preserve the given dependencies. Here’s why:
The original dependencies are A → B, B → C, A → D, and D → C.
In the decomposed relations, we have:
AB: This relation preserves the dependency A → B.
AC: This relation preserves the dependency A → D because D is functionally
determined by A, which in turn determines C. So, A can determine C.
BD: This relation preserves the dependency D → C.
So, all original dependencies are preserved in the decomposed relations. Therefore, the
decomposition ρ is dependency preserving.
6. Consider the relation scheme ABCD with dependencies
F={A B, B C, D B]
We wish to find a lossless-join decomposition into BCNF.
a) Suppose we choose, as our first step, to decompose ABCD into ACD and BD.
What are the projected dependencies in these two schemes?
b) Are these schemes in BCNF? If not, what further decomposition is necessary?
SOLUTION:
a) If we decompose ABCD into ACD and BD, the projected dependencies in these two
schemes are:
ACD: {A → B} (B can be inferred from A through the original dependency, and D
is also part of this scheme)
BD: {D → B}
b) The scheme ACD is not in BCNF because the left side of the dependency A → B is not
a superkey. The scheme BD is in BCNF because D → B has a superkey (D) on its left side.
To make ACD into BCNF, we need to further decompose it into AD and AB because A →
B is a violation in ACD. So, the final decomposition would be AB, AD, and BD.