Vous êtes sur la page 1sur 12

COMP231 Tutorial 5

Functional Dependencies and Normalization 1

Review: Functional Dependencies


FD Rules:
For a set of functional dependencies F, its closure F+ is the set of all
functional dependencies derived from F under the following rules:
R1: (Reflexivity)

If X Y, then X Y.

R2: (Augmentation)

If X Y, then XZ YZ.

R3: (Transitivity)

If X Y, Y Z, then X Z.

R4: (Decomposition)

If X YZ, then X Y and X Z.

R5: (Union)

If X Y and X Z, then X YZ.

Armstrongs
Axioms

R6: (Pseudotransitivity) If X Y and WY Z, then WX Z.

Database Management Systems

Department of Computer Science and Engineering, HKUST

Exercise: How to infer FDs?


Use the Armstrongs Axioms to prove the correctness of
R5: (Union)

If X Y and X Z, then X YZ.

1. X Y (given)
2. X XY (augmentation)
3. X Z (given)
4. XY YZ (augmentation)
5. X YZ (transitivity on 2 and 4)

Database Management Systems

Department of Computer Science and Engineering, HKUST

Exercise: How to infer FDs? (cont)


Does {WY, XZ} imply {WXY}?
Yes!
1. WY WXYX (augmentation)
2. YXY (reflexivity)
3. WXY (transitivity)
Does {XY, XW, WYZ} imply {XZ}?
Yes!
1. XY (given)
2. XW (given)
3. XWY (union)
4. WYZ (given)
5. XZ (transitivity)
Does {XYZ, YW} IMPLY {XWZ}?
No!
Database Management Systems

Department of Computer Science and Engineering, HKUST

Exercise: The Closure of Attributes


R = (A, B, C, D, E).
F = {ABC, CDE, BD, EA}.
Compute A+ and B+.
A+ = A

because AA

= ABC

because ABC

= ABCD

because BD

= ABCDE

because CDE

B+ = B
= BD

Database Management Systems

because BB
because BD

Department of Computer Science and Engineering, HKUST

Keys
Key: a set of attributes that uniquely identifies a tuple
Superkey: K R
Candidate Key: 1. K R
2. no K K, s.t. K R (minimal)
Primary Key: The candidate key chosen to uniquely
identify tuples in a relation

primary key

candidate key
superkey

Database Management Systems

Department of Computer Science and Engineering, HKUST

Exercise: Candidate Keys


R = (A, B, C, D, E).
F = {ABC, CDE, BD, EA}.
List all candidate keys of R.
(1)
Since AB and BD, then AD.

(decomposition, transitivity)

Since ACD and CDE, then AE. (decomposition, union


transitivity)
A A.

(reflexivity)

Therefore A ABCDE.
So A is a candidate key of R.

Database Management Systems

Department of Computer Science and Engineering, HKUST

Exercise: Candidate Keys (cont)


R = (A, B, C, D, E).
F = {ABC, CDE, BD, EA}.
(2)
Since EA, then EABCDE.

(transitivity)

So E is also a candidate key of R.


(3)
Since CDE, then CDABCDE.

(transitivity)

So CD is also a candidate key of R.


(4)
Since BD and BCCD, then BC ABCDE.

(augmentation,
transitivity)

So BC is also a candidate key of R.


Database Management Systems

Department of Computer Science and Engineering, HKUST

Compute Canonical Cover


R = ABCDEFGH
F = {ACG, DEG, BCD, CGBD, ACDB, CEAG}
Find the canonical cover of F.
1. Union
2. Find a redundant (extraneous) attribute
Consider ACDB, D is extraneous, because ACG and CGBD
imply ACCGB
So change ACDB into ACB
{ACG, DEG, BCD, CGBD, ACB, CEAG}

Database Management Systems

Department of Computer Science and Engineering, HKUST

Compute Canonical Cover (cont)


{ACG, DEG, BCD, CGBD, ACB, CEAG}
1. Union
{ACBG, DEG, BCD, CGBD, CEAG}
2. Find a redundant (extraneous) attribute
Consider ACBG, G is extraneous, because ACB, BCD, and
DEG imply AC D G
So change ACBG into ACB
{ACB, DEG, BCD, CGBD, CEAG}

Database Management Systems

10

Department of Computer Science and Engineering, HKUST

Compute Canonical Cover (cont)


{ACB, DEG, BCD, CGBD, CEAG}
1. Union
2. Find a redundant (extraneous) attribute
Consider CGBD, B is extraneous, because CGD, D EG,
CEAG, and AC B imply CG CD CE AC B
So change CG BD into CG D
{ACB, DEG, BCD, CGD, CEAG}
1. Union
2. Find a redundant (extraneous) attribute
Consider CE AG, G is extraneous, because CE A, AC B,
BCD, and D EG imply CE AC BC D G
So change CE AG into CE A
{ACB, DEG, BCD, CGD, CEA}
Database Management Systems

11

Department of Computer Science and Engineering, HKUST

Compute Canonical Cover (cont)


{ACB, DEG, BCD, CGD, CEA}
No more extraneous attributes
FC = {ACB, DEG, BCD, CGD, CEA}
Different order of considering the extraneous attributes can result in
different FC

Database Management Systems

12

Department of Computer Science and Engineering, HKUST

Vous aimerez peut-être aussi