Академический Документы
Профессиональный Документы
Культура Документы
Functional Dependencies
Relational Model:
plus FD’s
Normalization:
Eliminates anomalies
Functional Dependencies
Definition: A1, ..., Am B1, ..., Bn holds in R if:
R
A1 ... Am B1 ... Bm
t’
name
Product buys Person
Product sname
card-no
CreditCard
Person ssn
Product sname
Incomplete
card-no
CreditCard
Person ssn (what does
it say ?)
where i = 1, 2, ..., n
A1 ... Am
Why ?
Inference Rules for FD’s
(continued)
If A1 , A2, … An B1, B2 …, B m
then A1 , A2, … An C , C …, C
1 2 p
Why ?
A1 ... Am B1 ... Bm C1 ... Cp
• Enrollment(student, major, course, room, time)
student major
major, course room
course time
then
add C to X.
R(A,B,C,D,E,F) Example
A B C
A D E
B D
A F B
SSN PhoneNumber
123-45-6789 206-555-1234
123-45-6789 206-555-6543
987-65-4321 908-555-2121
987-65-4321 908-555-1234
Relational Schema Design
name
Relational Model:
plus FD’s
Normalization:
Eliminates anomalies
Decompositions in General
R(A1, ..., An)
Create two relations R1(B1, ..., Bm) and R2(C1, ..., Cp)
and:
R1 = projection of R on B1, ..., Bm
R2 = projection of R on C1, ..., Cp
Incorrect Decomposition
• Sometimes it is incorrect:
Name Price Category
Gizmo 19.99 Gadget
OneClick 24.99 Camera
DoubleClick 29.99 Camera
Others...
Boyce-Codd Normal Form
A simple condition for removing anomalies from relations:
AArelation
relationRRisisin
inBCNF
BCNFif:
if:
Whenever
Wheneverthere
thereisisaanontrivial
nontrivialdependency ...,AAnn
dependencyAA11,,..., BB
in
in RR,, {A
{A11,,...,
...,AAnn}} isisaakey
keyfor
forRR
SSN PhoneNumber
123-45-6789 206-555-1234
123-45-6789 206-555-6543
987-65-4321 908-555-2121
987-65-4321 908-555-1234
Summary of BCNF
Decomposition
Find a dependency that violates the BCNF condition:
A1 , A2, … An B1, B2, … B m
Heuristics: choose B1 , B2, … Bm“as large as possible”
Decompose:
Continue until
Others A’s B’s there are no
Is there a
BCNF violations
2-attribute
left.
relation that is
not in BCNF ? R1 R2
Example Decomposition
Person(name, SSN, age, hairColor, phoneNumber)
SSN name, age
age hairColor
• Key: A, D
• Violations of BCNF: A B, A C, A BC
• Pick A BC: split into R1(A,BC) R2(A,D)
• What happens if we pick A B first ?
Correct Decompositions
A decomposition is lossless if we can recover:
R(A,B,C)
Decompose
R1(A,B) R2(A,C)
Recover
R’(A,B,C) should be the same as
R(A,B,C)
R’ is in general larger than R. Must ensure R’ = R
Correct Decompositions
• Given R(A,B,C) s.t. AB, the
decomposition into R1(A,B), R2(A,C) is
lossless
3NF: A Problem with BCNF
Unit Company Product
Unit Product
No FDs
So What’s the Problem?
Unit Company Unit Product
Galaga99 UW Galaga99 databases
Bingo UW Bingo databases
No problem so far. All local FD’s are satisfied.
Let’s put all the data back into a single table again:
Galaga99 UW databases
Bingo UW databases
AArelation
relationRRisisin
in3rd
3rdnormal
normalform
formifif::
Whenever
Whenevertherethereisisaanontrivial
nontrivialdependency ...,AAnn
dependencyAA11,,AA22,,..., BB
for
for RR,,then
then {A
{A11,,AA22,,...,
...,AAnn}}aasuper-key
super-keyfor
forR,
R,
or
orBBisispart
partof
ofaakey.
key.