csci4380-week04a - Rensselaer Polytechnic Institute

advertisement
Rensselaer Polytechnic Institute
CSCI-4380 – Database Systems
David Goldschmidt, Ph.D.

Without normalization, problems with
relations include:
 Unnecessary redundancy
 Insert anomalies
 Update anomalies
 Delete anomalies

Splitting a relation into two (more specific)
relations is called decomposition
 The objective is to have each
resulting relation be atomic
 i.e. each relation should contain
only information related to the key

A given relation R with set F of functional
dependencies is in BCNF if and only if all
functional dependencies X  Y in F are:
 either trivial (i.e. Y  X)
 or X is a superkey of R

If relation R is not in BCNF, it is possible to
use decomposition to transform R to BCNF

Given a set F of functional dependencies for
relation R( A1, A2, ..., An ) that is not in BCNF:
 Convert F to a minimal basis
 Find an X  Y that violates BCNF
 Compute closure X+
 Decompose R into:
▪ R1 containing all attributes of X+
▪ R2 containing { A1, A2, ..., An } – ( X+ – X )
 Project functional dependencies onto R1 and R2

A decomposition of R into relations
R1, R2, ..., Rn is considered lossless if
for all possible instances of R, we
are guaranteed that:
 R1 ⋈ R2 ⋈ ... ⋈ Rn = R
 Note that the order of the natural joins
is not important since ⋈ is both associative
and symmetric

Decomposition (hopefully) achieves:
 Elimination of anomalies: remove redundancy
and update/insert/delete anomalies
 Recoverability of information: can we recover
the original relation from its decomposition?
 Preservation of dependencies:
can we reconstruct the original
functional dependencies?

A given relation R with set F of functional
dependencies is in 3NF if and only if all
functional dependencies X  Y in F are:
 trivial (i.e. Y  X)
 or X is a superkey of R
 or all attributes of Y are prime attributes

A prime attribute is an attribute that is a
member of some key of relation R

Given a set F of functional dependencies for
relation R( A1, A2, ..., An ) that is not in 3NF:
 Convert F to a minimal basis
 Combine all functional dependencies with
the same left-hand side
 Set D = { }
 For each functional dependency X  Y in F:
▪ If there is no relation in D that contains all attributes in
X and Y, then add a relation with attributes X  Y to D
 If there are no relations in D that have all
attributes of one of the keys of R, then add a
new relation to D that contains all attributes in
one of the keys of R
 Simplify D by removing redundancy:
▪ if R1 and R2 are in D, but R2 contains all
attributes of R1, then remove R1

The 3NF decomposition algorithm
guarantees the following:
 The resulting relations are in 3NF
 The decomposition is dependency preserving
 The decomposition is lossless

Given relation R( A, B, C, D, E, F ) and
functional dependencies AB  AC,
CE  DB, B  A, and D  AE
 What are the keys of R?
 What are the superkeys of R that are not keys?
 Is relation R in 3NF? If not, decompose R such
that it is in 3NF
Download