You are on page 1of 15

Canonical Cover &

Normal Forms

1
Canonical Cover

 The number closure computation depends on the


number of FD’s in F
 Question: Can we “minimize” F?
 Let F and G be sets of FD’s. F ≡ G iff F+ ≡ G+
 If F ≡ G we may say: G is a cover of F and vice
versa

2
Canonical Cover
 A canonical / minimal cover of F is a set G of
FDs that satisfies the following:
1. G is equivalent to F; that is, G ≡ F
2. G is minimal; that is, if we obtain a set H of FD’s
from G by deleting one or more of its FD’s, or by
deleting one or more attributes from some FD in
G, then F ≢ H
3. Every FD in G is of the form X  A, where A is a
single attribute 3
Computing Canonical Cover
 Step 1: Put the FD’s in the simple form
 Initialize G := F
 Replace each FD X → A1A2…Ak in G with X→A1,
X→A2, …, X→Ak
 Step 2: Minimize the left hand side of each FD
 E.g., for each FD AB → C in G, check if A or B on the
LHS is redundant , i.e., (G  {AB → C } ⋃ {A → C })+ ≡
F+?
 Step 3: Delete redundant FD’s
 For each FD X → A in G, check if it is redundant, i.e.,
whether (G  {X → A })+ ≡ F+?
4
Exercise #1
 Consider R = {A, B, C, D, E, F, G, H} with a
set of FDs
 F = {CD→A, EC→H, GHB→AB, C→D,
EG→A, H→B, BE→CD, EC→B}

Find a canonical cover for F

5
Normal Forms

 Given a relation schema R, we want to determine


whether it has problems related to redundancy. If
so, we need to decompose it into smaller relations.
 To address these issues, we need to study normal
forms

6
Types of Normal Forms
 Examples of normal forms:
 First normal form (1NF)
 Second normal form (2NF)
 Third normal form (3NF)
 Boyce-Codd normal form (BCNF)
 These normal forms have increasingly restrictive
requirements

BCNF 3NF 2NF 1NF

7
First Normal Form (1NF)
 A relation schema R is in the first normal
form if the domain of its each attribute has
only atomic values (No attribute is allowed to
be composite or multi valued)
 Example: The following relation is not in 1NF
 Student (SID, SName, {(CourseId, CouseName,
Grade)})

8
Second Normal Form (2NF)
 A relation schema R w.r.t. F is in 2NF if:
1. It is in 1NF
2. Every Non-Primary-Key attribute is fully
functionally dependent upon the ENTIRE
Primary-Key for its existence
 For each non-key attribute, ask:
 If I knew the value for part of the Primary-Key,
could I tell what the value for non-key attribute
would be?

9
2NF – Example - 1
 Inventory (Item, Supplier, Cost, Supplier Address)
 We first check if Cost is fully functionally dependent upon
the ENTIRE Primary-Key
 If I know just Item, can I find out Cost?
 No. We can have > 1 supplier for the same product.

 If I know just Supplier, and I find out Cost?


 No. We need to know what the Item is as well.

 So, Cost is fully functionally dependent upon the


ENTIRE Primary-Key

10
2NF – Example - 2
 Inventory (Item, Supplier, Cost, Supplier Address)
 We then check if Supplier Address is fully functionally
dependent upon the ENTIRE Primary-Key
 If I know just Item, can I find out Supplier Address?
 No. We can have > 1 supplier for the same product.

 If I know just Supplier, and I find out Supplier Address?


 Yes. The supplier’s address does not depend on the
Item.
 So, Supplier Address is NOT fully functionally
dependent upon the ENTIRE Primary-Key  NOT 2NF
11
Third Normal Form (3NF)
 A relation schema R w.r.t. F is in 3NF if, for every
FD X  A in F, at least one of the following
conditions holds:
 A  X, that is, X  A is a trivial FD, or
 X is a superkey, or
 If X is not a key, then A is part of some key of R
 To determine if a relation <R, F> is in 3NF, we
 Check whether the LHS of each nontrivial FD in
F is a superkey
 If not, check whether its RHS is part of any key
of R
12
Boyce-Codd Normal Form (BCNF)

A relation schema R w.r.t. F is in BCNF if, for


every FD X  A in F, at least one of the following
conditions is true:
 A  X, that is, X  A is a trivial FD, or

 X is a super key

 To determine whether R w.r.t. F is in BCNF


 Check whether the LHS X of each nontrivial FD
in F is a superkey
 How? Simply compute X+ (w.r.t. F) and check
if X+ = R
13
Exercise #2
 Consider R = {A, B, C, D, E, F, G, H} with a
set of FDs
 F = {CD→A, EC→H, GHB→AB, C→D,
EG→A, H→B, BE→CD, EC→B}

Is R w.r.t. F in 3NF?

14
Exercise #3
 Consider R = {A, B, C, D, E, F, G} with a set
of FDs
 F = {ABC→DE, AB→D, DE→ABCF, E→C}
 Is R in BCNF, 3NF, or neither?

15

You might also like