4 Normal Forms Post 3
4 Normal Forms Post 3
Normalization 1
Reminders and Important Dates
Feb 06, 2020
Midterm 1 information
• Tuesday February 11 @ 7PM (next week)
• Duration : 50 minutes
• Covers up until BCNF (3NF will NOT be on midterm 1)
• Check the Piazza post which contains additional information
• Lot of practice material + previous midterm exam samples available on
canvas
Normalization 3
Previously…
• We started looking at normalization
• 1NF (only one value per attribute)
• 2NF (All nonkey attributes in the table must be functionally
dependent on the entire primary key)
Normalization 4
Previously…2NF
City, Street, HouseNumber → HouseColor
City → CityPopulation
Normalization 5
Previously…
• We started looking at normalization
• 1NF (only one value per attribute)
• 2NF (All nonkey attributes in the table must be functionally
dependent on the entire primary key)
• BCNF (X→ b then X must be a sk)
Normalization 6
Try!
PID Name Age canDrive Phone#
P1 John 14 No 604 111 1111
P2 Raj 28 Yes 604 111 1111
P3 John 14 No 604 333 3333
PID → Name
Age → canDrive
Is the relation in BCNF? If not, decompose this relation into BCNF
Normalization 7
Sol
PID Name Age canDrive Phone# PID → Name
P1 John 14 No 604 111 1111 Age → canDrive
P2 Raj 28 Yes 604 111 1111
P3 John 14 No 604 333 3333
John T1 G1 2
John T2 G3 1
Linda
(University of Waterloo)
T1 G2
Normalization Theory
1
Normalization 9
Previously… Lossless-Join
Decompositions
• We should be able to construct the instance of the original table from the
instances of the tables in the decomposition
SName TutorialNum TutorialGroup Marks
John T1 G1 2
John T2 G3 1
Linda
(University of Waterloo)
T1 G2
Normalization Theory
1
Normalization 12
FD Preservation
• Given a relation R and a set of FDs F, decompose R into
R1 and R2
• Suppose
– R1 has a set of FDs F1
– R2 has a set of FDs F2
– F1 and F2 are computed from F.
Normalization 13
Example
Normalization 14
Example : FD Preservation
PID Name Age canDrive Phone# PID → Name
P1 John 14 No 604 111 1111 Age → canDrive
P2 Raj 28 Yes 604 111 1111
P3 John 14 No 604 333 3333
Normalization 15
After you decompose, how do you
know which FDs apply?
• For an FD X→b,
• if the decomposed relation S contains {X U b}, and
• b X+ t
• then the FD holds for S:
Normalization 17
Clicker Question
• Consider relation R(A,B,C,D,E) with functional dependencies AB → C, BC → D,
CD → E, DE → A, and AE → B. Project these FD's onto the relation S(A,B,C,D).
AE→ B No No
Note that we use all FDs for finding closures, so for (D) option we use DC→E
even though E is not present in S.
Normalization 18
Midterm cut-off
• Closed book exam
• Comprehensive covering everything up to FD
preservation
• Introduction to DB
• ERD
• RS
• Normalization (up to BCNF – FD, Anomalies, 1NF, 2NF,
BCNF, lossless join decomposition, FD preservation)
Normalization 19
Outline
1. Recap
2. FD Preservation
3. 3NF
4. Revisit learning objectives
Normalization 20
What is offered by 3NF decomposition?
Normalization 21
3NF come to Rescue!
Normalization 22
23
Normalization 23
24
• Unit → Company
FDs
• Company, Product → Unit
Normalization 24
25
Normalization 25
Minimal Cover for a Set of FDs
• Sets of functional dependencies may have redundant
dependencies that can be inferred from the others .
• Eg: A → C is redundant in: {A → B, B → C, A → C}
Normalization 26
Minimal Cover for a Set of FDs
• A minimal cover of a set of dependencies, F, is a set of
dependencies, U, such that:
• U is equivalent to F (F+ = U+)
• FDs and attributes that can be deleted in this way are called
redundant
Normalization 27
Minimal Cover
• Intuitively, every FD in U is needed, and is “as small as
possible’’ in order to get the same closure as F
A→B, A→B,
minimal cover ACD→E,
ABCD→E,
EF→GH, EF→G,
ACDF→EG EF→H,
F U
Normalization 28
Finding minimal covers of FDs
1. Put FDs in standard form (have only one attribute on RHS)
2. Minimize LHS of each FD
3. Delete Redundant FDs
Normalization 29
Finding minimal covers of FDs
1. Put FDs in standard form (have only one attribute on RHS)
2. Minimize LHS of each FD
A→B
3. Delete Redundant FDs
ABCD→E
EF→G
Example: EF→H
ACDF→EG
Replace ACDF→EG with
• ACDF → E
• ACDF → G
Normalization 30
Finding minimal covers of FDs
1. Put FDs in standard form (have only one attribute on RHS)
2. Minimize LHS of each FD
3. Delete Redundant FDs
Algorithm:
Remove B from the left-hand-side of X → A in F if A is in X+(X-{B},F).
Example:
ABCD→E
ABCD : can we get E now? We check for all subsets
ABCD : can we get E now? by eliminating one
ABCD : can we get E now? attribute at a time
ABCD : can we get E now?
Normalization 31
Finding minimal covers of FDs
Reduce LHS Final FDs
1. Put FDs in standard form
(have only one attribute on A→B
RHS) ABCD→E
2. Minimize LHS of each FD
3. Delete Redundant FDs
EF→G
A→B
ABCD→E EF→H
EF→G
EF→H ACDF→E
ACDF→E
ACDF→G
ACDF→G
Normalization 32
Finding minimal covers of FDs
1. Put FDs in standard form (have only one attribute on RHS)
2. Minimize LHS of each FD
A→B
3. Delete Redundant FDs ACD→E
EF→G
EF→H
ACD→E
ACDF→G
Normalization 33
A→B
ACD→E
EF→G
ACD→ E
EF→G
EF→H
ACDF→G
Normalization 34
Final answer
A→B A →B
ABCD→E ACD→ E
EF→G EF→G
EF→H EF→H
ACDF→EG
Minimal Cover
Normalization 35
Find the minimal cover - Try!
• R(ABCD)
• F = {A → BC, B → C, AB → D}
Normalization 36
Find the minimal cover
• R(ABCD)
• F = {A → BC, B → C, AB → D}
1. Reduce RHS 2. Reduce LHS
Given FDs Test for the reduction of Write FDs after
Given FDs Write FDs after LHS reducing LHS
reducing RHS A→B We can’t reduce LHS A→B
A→ BC A→B
A→C We can’t reduce LHS A→C
A→C
B→C B→C B→C We can’t reduce B→C
A+ includes D, so B is
extraneous, ie., we can
identify D without B on the
LHS.
Normalization 37
Find the minimal cover
3. Remove Redundant FD F = {A→B , A→C , B→C , A→D}
Normalization 38
Now we’re ready to decompose into
3NF
• We’ll cover two methods.
Normalization 39
Decomposition into 3NF using
Minimal Cover
• Decomposition into 3NF:
• Given the FDs F, compute F': the minimal cover for F
• Decompose using F' if violating 3NF similar to how it was
done for BCNF
• After each decomposition identify the set of dependencies
N in F' that are not preserved by the decomposition.
• For each X→a in N create a relation Rn(X a) and add it to
the decomposition
Normalization 40
3NF Example
Relation: R(ABCDE)
• FD: AB→C, C→D
Normalization 41
Your turn!
Let R(CSJDPQV) be a relation with the following FDs
SD→P
JP→C
J→S
• Is this in 3NF? If not, decompose R into 3NF
Normalization 42
Your turn!
Let R(CSJDPQV) be a relation with the following FDs
• SD→P
• JP→C
• J→S
• Is this in 3NF? If not, decompose R into 3NF .
• Already in minimal cover
SD+=SDP
JP+= JPSC
J+=JS
JDQV+ = CSJDPQV Key
Normalization 43
Your turn!
• Let R(CSJDPQV) be a relation FDs SD→P, JP→C , J→S
SD → P R(CSJDPQV
(Violate 3NF) J→S
(Violate 3NF)
R1(SDP) R2(CSJDQV)
R3(JS) R4(CJDQV)
• No more violations!
• Are all FDs preserved? JP→C ? No so add R5(CJP)
• Final answerR1(SDP), R3(JS), R4(CJDQV) , R5(CJP)
Normalization 44
3NF Synthesis
• Conceptually simpler.
• Given a set of FDs 𝐹, obtain a minimal cover 𝐹’
• ∀FD 𝑋 → 𝐴 ∈ 𝐹 ′ , create a scheme 𝑋𝐴.
• Resulting decomposition is guaranteed to preserve all FDs
(trivially) and each scheme is in 3NF. But no guarantee for
LLJ!
• Easy fix: add any schema that contains a key of the
original relation scheme 𝑅.
Normalization 45
Example: Decomposition into 3NF Using
a Minimal Cover and 3NF Synthesis
• Suppose we have R(A,B,C) with FDs: A → B, C → B.
1. Find a minimal cover F'. Already done.
2. For each FD X→b, add relation Xb to
the decomposition for R.
• Result: R1(A,B) and R2(B,C). Are we done? No.
3. Does it contain a key? What are the keys of R? AC.
Add R3(A,C).
Normalization 46
Consider the following set of tuples
with the previous relation and FDs
Maintains A→B
A B
A→B
1 2 Maintains C→B
C→B 1 2 and A→B
2 2
A B C
A B C 1 2 3
Decompose Natural
1 2 3
Join 1 2 4
1 2 4 2 2 4
B C
2 2 4 2 2 3
2 3
2 4
2 4
Not lossless!
Maintains C→B
Normalization 47
Consider the following set of tuples
with the previous relation and FDs
Maintains A→B
A B
A→B
1 2 Maintains C→B
C→B 1 2 and A→B
2 2
A B C
A B C 1 2 3
Decompose Natural
1 2 3
Join 1 2 4
1 2 4 2 2 4
B C
2 2 4 2 2 3
2 3
2 4
2 4
Not lossless!
Maintains C→B
Normalization 48
Take two!
Maintains A→B
A B
1 2
A→B Maintains C→B
1 2
C→B and A→B
2 2
A B C
A B C Maintains C→B
1 2 3
1 2 3 Decompose B C Natural 1 2 4
2 3 Join
1 2 4 2 2 4
2 4
2 2 4
2 4 Lossless!
Key! Can’t get (2, 2, 3)
A C because there is
1 3 no (2, 3) tuple in
1 4 R3(A,C)
2 4 105
In decompositions, you can often make some
adjustments to make a “better” decomposition
Normalization 50
3NF Synthesis – Try!
Relation: R(ABCDE)
• FD: AB→C, C→D
Normalization 51
3NF Synthesis – Try!
Relation: R(ABCDE) Cover is already minimal
AB+ = ABCD
• FD: AB→C, C→D C+= CD
ABE+ = ABCDE only key
R1 (ABC)
R2 (CD)
R3 (ABE)
Normalization 52
Question: BCNF and 3NF
Consider the following relation and functional dependencies:
R(ABCD)
FD's: ACD → B ; AC → D ; D → C ; AC → B
Normalization 53
BCNF and 3NF
Consider the following relation and functional dependencies:
R(ABCD)
FD's: ACD → B ; AC → D ; D → C ; AC → B
Normalization 54
Comparing BCNF & 3NF
• BCNF guarantees removal of all anomalies
• 3NF has some anomalies, but preserves all dependencies
• If a relation R is in BCNF it is in 3NF.
Normalization 55
Other normal forms
• Further normal forms exist which deal with issues not
covered by functional dependencies
• Fourth Normal Form deals with multi-valued dependencies
• Fifth Normal Form addresses more complex (and rarer) situations
where 4NF is not sufficient
Normalization 56
Normalization and Design
Normalization 57
Normalization Drawbacks
• By limiting redundancy, normalization helps maintain consistency
and saves space
Normalization 59
Learning Goals Revisited
1. Debate the pros and cons of redundancy in a database.
2. Provide examples of update, insertion, and deletion
anomalies.
3. Given a set of tables and a set of functional dependencies
over them, determine all the keys for the tables.
4. Show that a table is/isn’t in 3NF or BCNF.
5. Prove/disprove that a given table decomposition is a
lossless join decomposition. Justify why lossless join
decompositions are preferred decompositions.
6. Decompose a table into a set of tables that are in 3NF, or
BCNF.
Normalization 60
Normalization
Consider the following database schema (R) . The attributes are ABCDEF. The
FDs are:
• ABF → C
• CF → B
• CD → A
• BD → AE
• C→F
(a) Which of the above 5 FDs, if any, violate BCNF? No explanation needed.
Normalization 61
Normalization
Consider the following database schema (R) . The attributes are ABCDEF. The
FDs are:
• ABF → C
• CF → B
• CD → A
• BD → AE
• C→F
(a) Which of the above 5 FDs, if any, violate BCNF? No explanation needed.
All violates except CD→A
Normalization 62
(b)
Normalization 63