Download Functional Dependencies and Normalization in Relational Databases and more Exercises Law in PDF only on Docsity!
Chapter 3 Design Theory for
Relational Databases
Objectives
Understand concepts of:
Functional Dependencies – phụ thuộc hàm
Normalization – chuẩn hóa
Decomposition – phân rã
Multi-valued Dependencies - Phụ thuộc đa trị
Functional dependency
Functional dependency
Functional dependency
Easy to see that: the following FD is true
title,year length, genre, studioName
Exercise: How about the FD
title,year starName
title, year startName does not hold in Movies1 relation
Functional dependency
Review key of relation, candidate keys(alternate
keys), primary key
Super-key
A set of attributes that contains a key is called a super-
key
Every super-key satisfies the first condition of a key: it
functionally determines all other attributes of the
relation
If K is a key, L is a super key, then: K L
A key is also a super key
Functional dependency
A set of FD’s S follows from a set of FD’s T
if every relation instance that satisfies all the FD’s in T
also satisfies all the FD’s in S
Two sets of FD’s S and T are equivalent if and only if S
follows from T , and T follows S
Example 3.
relation R(A,B,C,D,E,G,H)
A set of functional dependencies
F={ ABC, BD, CD E, CE GH, G A}
Use the Armstrong axioms to prove the
following deductions AB E
The closure of a set of attributes { A
1
, A
2
, …, A
n
} under
FD’s in S (denoted { A
1
, A
2
, …, A
n
) is the set of
attributes B such that every relation that satisfies all the
FD’s in set S also satisfies A
1
A
2
…A
n
B
That is, A
1
A
2
…A
n
B follows from the FD’s of S
A
1
, A
2
, …, A
n
{ A
1
, A
2
, …, A
n
}+, because A
1
A
2
…A
n
A
i
is
trivial
The Closure of Attributes
Algorithm 3.7: Closure of a set of attributes
Input: A set of attributes { A
1
,A
2
,…,A
n
} and a set of FD’s
S
Output: The closure { A
1
,A
2
,…,A
n
- If necessary, split the FD’s of S , so each FD in S have
singleton right side
- Let X be a set of attributes that will become the closure.
Initialize X to be { A 1
,A 2
,…,A n
}
- Repeatedly search for some FD: B 1
B 2
…B m
C , such that B 1
,
B 2
, …, B m
are in X , but C is not
a) If such C is found, add to X, and repeat the search
b) If such C is not found, no more attributes can be added to X
- The set X is the correct value of {A 1
, A 2
, …, A n
}+
The Closure of Attributes
R(A, B, C, D)
S={A→B, B→C, C→D, D→A}
Compute {A}
? {B}
What are some the keys of R?
The Closure of Attributes
Suppose a set of FD’s S , any set of FD’s T equivalent
to S is said to be a basis for S.
Then we say T is a basis for S
Just work with only FD’s that have singleton right
sides
A minimal basis for FD’s S is a basis B that satisfies
three conditions:
All the FD’s in B have singleton right sides
If any FD is removed from B , the result is no longer
a basis
If for any FD in B we remove one or more attributes
from the left side, the result is no longer a basis
Closing Sets of Functional Dependencies
Closing Sets of Functional Dependencie
Relation R(U), U={A, B, C, X, Z},
F = { A → B, C → X, BX → Z}
{ AC → Z} F
?
- A → B (hypothetically)
- AX → BX (Augmentation)
- BX → Z (hypothetically)
- AX → Z (Transitivity 2&3)
- C → X (hypothetically)
- AC → AX (Augmentation)
- AC → Z (Transitivity 6&4)
Example
R(A,B,C)
S={AB, A C, B A, B C, C A, C B, AB C,
BC A, AC B, A BC, B AC, C AB}
R and its FD’s have several minimal basis
{A B, B A, B C, C B}, or
{A B, B C, C A}
Closing Sets of Functional Dependencies