Lect12 3NF
Lect12 3NF
Database Systems
1
Last Lecture
BCNF Definition:
A table R is in BCNF, if every non‐trivial and decomposed
FD has a superkey as its left hand side
BCNF Check:
Check if there exists a “more but not all” closure
E.g., a table R(X, Y, Z), with {X}+ = {X, Y}
BCNF Decomposition
If we have a table a table R(X, Y, Z), with {X}+ = {X, Y}
Then decompose R into R1(X, Y) and R2(X, Z)
Repeat until all tables are in BCNF
2
Properties of BCNF
Good properties
No update or deletion anomalies
Small redundancy
The original table can always be reconstructed from
the decomposed tables
Bad properties
Dependencies may not be preserved in the
decomposed table
3
Dependency Preservation
Given: Table R(A, B, C) R A B C
with ABC, CB
Keys: {AB}, {AC}
BCNF Decomposition R1 R2
R1(B, C) B C A C
R2(A, C)
Non‐trivial and decomposed FDs on R1: CB
Non‐trivial and decomposed FDs on R2: none
The other FD, ABC, cannot be derived from the FDs
on R1 and R2, i.e., it is “lost”
This why we say that a BCNF decomposition may not
always preserve all FDs
4
Dependency Preservation
Let S be the given set of FDs on the original table
Let S' be the set of FDs on the decomposed tables
We say that the decomposition preserves all FDs, if
and only if S and S' are equivalent, i.e.,
Every FD in S' can be derived from S
Every FD in S can be derived from S' R A B C
Example:
1 R R2
S = {AB, BC, AC}
S' = {AB, BC} B C A B
S' can obviously be derived from S
S can also be derived from S', since
AB, BC ==> AC (just check {A}+ given S')
Hence, S and S' are equivalent
5
FD Equivalence: Example
S = {AC, ACD, EAD, EH}
S' = {ACD, EAH}
Prove that S and S' are equivalent
First, prove that S' can be derived from S
Given S, we have {A}+ = {ACD}, so ACD is implied by S
Given S, we have {E}+ = {EADHC}, so EAH is implied
by S
Hence, S' can be derived from S
6
FD Equivalence: Example
S = {AC, ACD, EAD, EH}
S' = {ACD, EAH}
Prove that S and S' are equivalent
Second, prove that S can be derived from S'
Given S', we have {A}+ = {ACD}, so AC is implied by S'
Given S', we have {AC}+ = {ACD}, so ACD is implied by
S'
Given S', we have {E}+ = {EADHC}, so EAD and EH
are implied by S'
Hence, S can be derived from S'
7
Dependency Preservation
What is the point of preserving FDs? R A B C
It makes it easier to avoid
“inappropriate” updates
R1 R2
Previous example B C A C
We have two tables R1(B, C), R2(A, C)
We have CB and ABC
Due to ABC, we are not supposed to have two tuples
(a1, b1, c1) and (a1, b1, c2)
But as we store A and C separately in R1 and R2, it is not easy to
check whether such two tuples exist at the same time
That is, if someone wants to insert (a1, b1, c2), it is not easy for
us to check whether (a1, b1, c1) already exists
This could be undesirable, depending on the application
8
Roadmap
BCNF
Small redundancy
Lossless join property
But may not preserve all FDs
Third Normal Form (3NF)
Not as strict as BCNF
Small redundancy (not as small as BCNF, though)
Lossless join property
Preserve all FDs
9
Third Normal Form (3NF)
Definition: A table satisfies 3NF, if and only if for
every non‐trivial and decomposed FD
Either the left hand side is a superkey
Or the right hand side is a prime attribute (i.e., it appears in
a key)
Example:
Non‐trivial and decomposed FDs: CB, ACB, ABC
Keys: {AB}, {AC}
CB is OK, since B is a prime attribute R A B C
ACB is OK, since AC is a key of R
ABC is OK , since AB is a key of R
So R is in 3NF
10
Third Normal Form (3NF)
Definition: A table satisfies 3NF, if and only if for
every non‐trivial and decomposed FD
Either the left hand side is a superkey
Or the right hand side is a prime attribute (i.e., it appears in
a key)
Another example:
Non‐trivial and decomposed FDs: AB, BC, ACB, ABC
Keys: {A}
AB is OK, since A is a superkey of R R A B C
BC is not OK, since B is not a superkey of R,
and C is not a prime attribute
So R is NOT in 3NF
11
BCNF vs. 3NF
BCNF: For any non‐trivial 3NF: For any non‐trivial
and decomposed FD, and decomposed FD,
The left hand side is a super‐ Either the left hand side is a
key super‐key
Or the right hand side is a
prime attribute
"Every attribute must depend "Exceptions can be made for
ONLY on superkeys!" prime attributes :P"
"No exception!"
3NF is more "lenient" than BCNF
Therefore,
Satisfying BCNF ==> satisfying 3NF, but not necessarily vice
versa
Violating 3NF ==> violating BCNF, but not necessarily vice
versa
13
3NF Check
Input: a table R
1. Compute the closure for each subset of the
attributes in R
2. Derive the keys of R
3. For each closure {X1, …, Xk}+ = {Y1, …, Ym}, check if
{Y1, …, Ym} does not contain all attributes, and
there is an attribute in {Y1, …, Ym} that is not in {X1, …, XK}
and is not a prime attribute
4. If such a closure does not exist, then R is in 3NF
14
3NF Check: Example
R(A, B, C, D) with FDs AB C, C D, and DA
1. Compute the closure for each subset of the attributes in R
{A}+= {A}, {B}+= {B}, {C}+= {ACD}, {D}+= {AD}
{AB}+= {ABCD}, {AC}+= {ACD}, {AD}+= {AD}
{BC}+= {ABCD}, {BD}+= {ABCD}, {CD}+= {ACD}
{ABC}+= {ABD}+= {BCD}+ = {ABCD}
{ACD}+ = {ACD}
{ABCD}+ = {ABCD}
15
3NF Check: Example
R(A, B, C, D) with FDs AB C, C D, and DA
2. Derive the keys of R
Keys: AB, BC, BD
{A}+= {A}, {B}+= {B}, {C}+= {ACD}, {D}+= {AD}
{AB}+= {ABCD}, {AC}+= {ACD}, {AD}+= {AD}
{BC}+= {ABCD}, {BD}+= {ABCD}, {CD}+= {ACD}
{ABC}+= {ABD}+= {BCD}+ = {ABCD}
{ACD}+ = {ACD}
{ABCD}+ = {ABCD}
16
3NF Check: Example
Keys: AB, BC, BD
R(A, B, C, D) with FDs AB C, C D, and DA
3. For each closure {X1, …, Xk}+ = {Y1, …, Ym}, check if
(i) {Y1, …, Ym} does not contain all attributes, and
(ii) there is an attribute in {Y1, …, Ym} that is not in {X1, …, XK}
and is not a prime attribute
+ + + +
{A} = {A}, {B} = {B}, {C} = {ACD}, {D} = {AD}
+ + +
{AB} = {ABCD}, {AC} = {ACD}, {AD} = {AD}
+ + +
{BC} = {ABCD}, {BD} = {ABCD}, {CD} = {ACD}
+ + +
{ABC} = {ABD} = {BCD} = {ABCD}
+
{ACD} = {ACD}
In 3NF
+
{ABCD} = {ABCD}
17
Exercise: 3NF Check
R(A, B, C, D) with FDs B C, B D
18
Exercise: 3NF Check
R(A, B, C, D) with FDs B C, B D
1. Compute the closure for each subset of the attributes
in R
+ + + +
{A} = {A}, {B} = {BCD}, {C} = {C}, {D} = {D}
+ + +
{AB} = {ABCD}, {AC} = {AC}, {AD} = {AD}
+ + +
{BC} = {BCD}, {BD} = {BCD}, {CD} = {CD}
+ +
{ABC} = {ABD} = {ABCD}
+ +
{BCD} = {BCD}, {ACD} = {ACD}
+
{ABCD} = {ABCD}
19
Exercise: 3NF Check
R(A, B, C, D) with FDs B C, B D
2. Derive the keys of R
{A}+= {A}, {B}+= {BCD}, {C}+= {C}, {D}+= {D}
{AB}+= {ABCD}, {AC}+= {AC}, {AD}+= {AD}
{BC}+= {BCD}, {BD}+= {BCD}, {CD}+= {CD}
{ABC}+= {ABD}+= {ABCD}
{BCD}+ = {BCD}, {ACD}+ = {ACD}
{ABCD}+ = {ABCD}
20
Exercise: 3NF Check
R(A, B, C, D) with FDs B C, B D
2. Derive the keys of R
keys: AB
+ + + +
{A} = {A}, {B} = {BCD}, {C} = {C}, {D} = {D}
+ + +
{AB} = {ABCD}, {AC} = {AC}, {AD} = {AD}
+ + +
{BC} = {BCD}, {BD} = {BCD}, {CD} = {CD}
+ +
{ABC} = {ABD} = {ABCD}
+ +
{BCD} = {BCD}, {ACD} = {ACD}
+
{ABCD} = {ABCD}
21
Exercise: 3NF Check
R(A, B, C, D) with FDs B C, B D
2. Derive the keys of R
keys: AB
+ + + +
{A} = {A}, {B} = {BCD}, {C} = {C}, {D} = {D}
+ + +
{AB} = {ABCD}, {AC} = {AC}, {AD} = {AD}
+ + +
{BC} = {BCD}, {BD} = {BCD}, {CD} = {CD}
+ +
{ABC} = {ABD} = {ABCD}
+ +
{BCD} = {BCD}, {ACD} = {ACD}
+ Not in 3NF
{ABCD} = {ABCD}
3. For each closure {X1, …, Xk}+ = {Y1, …, Ym}, check if
(i) {Y1, …, Ym} does not contain all attributes, and
(ii) there is an attribute in {Y1, …, Ym} that is not in {X1, …, XK} and is
not a prime attribute
22
Exercise: 3NF Check
23
Exercise: 3NF Check
In 3NF
R(A, B, C, D) with FDs A B, B C, CD, and DA
1. Compute the closure for each subset of the attributes in R
{A}+= {ABCD}, {B}+= {ABCD}, {C}+= {ABCD}, {D}+= {ABCD}
The others are all {ABCD}
2. Find the keys: A, B, C, D
3. For each closure {X1, …, Xk}+ = {Y1, …, Ym}, check if
(i) {Y1, …, Ym} does not contain all attributes, and
(ii) there is an attribute in {Y1, …, Ym} that is not in {X1, …, XK}
and is not a prime attribute
24
Exercise: 3NF Check
R(A, B, C, D, E) with FDs AB C, DE C, BE
25
Exercise: 3NF Check
R(A, B, C, D, E) with FDs AB C, DE C, BE
1. Compute the closure for each subset of the attributes
in R
2. Derive the keys of R
3. For each closure {X1, …, Xk}+ = {Y1, …, Ym}, check if
(i) {Y1, …, Ym} does not contain all attributes, and
(ii) there is an attribute in {Y1, …, Ym} that is not in {X1, …, XK} and
is not a prime attribute
4. If such a closure does not exist, then R is in 3NF
26
Exercise: 3NF Check
R(A, B, C, D, E) with FDs AB C, DE C, BE
1. Compute the closure for each subset of the attributes
in R
2. Derive the keys of R
Notice that A, B, and D do not appear in the r.h.s. of any FD
So all keys must contain ABD
{ABD}+ = {ABCDE}, so ABD is the only key
3. For each closure {X1, …, Xk}+ = {Y1, …, Ym}, check if
(i) {Y1, …, Ym} does not contain all attributes, and
(ii) there is an attribute in {Y1, …, Ym} that is not in {X1, …, XK} and
is not a prime attribute
4. If such a closure does not exist, then R is in 3NF
27
Exercise: 3NF Check
R(A, B, C, D, E) with FDs AB C, DE C, BE
1. Compute the closure for each subset of the attributes
in R
2. Derive the keys of R: ABD is the only key
3. For each closure {X1, …, Xk}+ = {Y1, …, Ym}, check if
(i) {Y1, …, Ym} does not contain all attributes, and
(ii) there is an attribute in {Y1, …, Ym} that is not in {X1, …, XK} and
is not a prime attribute
4. If such a closure does not exist, then R is in 3NF
28
Exercise: 3NF Check
R(A, B, C, D, E) with FDs AB C, DE C, BE
1. Compute the closure for each subset of the attributes
in R
+ +
{A} = {A}, {B} = {BE}
Violation found!
Not in 3NF
2. Derive the keys of R: ABD is the only key
3. For each closure {X1, …, Xk}+ = {Y1, …, Ym}, check if
(i) {Y1, …, Ym} does not contain all attributes, and
(ii) there is an attribute in {Y1, …, Ym} that is not in {X1, …, XK} and
is not a prime attribute
4. If such a closure does not exist, then R is in 3NF
29
3NF Decomposition
Given: A table NOT in 3NF
Objective: Decompose it into
smaller tables that are in 3NF R A B C D
Example
Given: R(A, B, C, D) R1 R2
FDs: ABC, CB, AD A B C A D
Keys: {AB}, {AC}
R is not in 3NF, due to AD
3NF decomposition of R:
R1(A, B, C), R2(A, D)
30
BCNF Decomposition vs. 3NF Decomposition
A BCNF decomposition A 3NF decomposition
may perform multiple has only one split,
splits, each of which which divides the table
divides a table into two into two or more parts
31
3NF Decomposition Algorithm
Given: A table R, and a set S of FDs
e.g., R(A, B, C, D)
S = {ABD, ABC, CD, BCD} R A B C D
Step 1: Derive a minimal basis of S
e.g., a minimal basis of S is
{AB, AC, CD}
R1 R2
Step 2: In the minimal basis, combine the FDs
whose left hand sides are the same A B C C D
e.g., after combining AB and AC,
we have {ABC, CD}
Step 3: Create a table for each FD remained
R1(A, B, C), R2(C, D)
Step 4: If none of the tables contains a key of
the original table R, create a table that
contains a key of R (any key would do)
32
Minimal Basis
Given a set S of FDs, the minimal basis of S is a
simplified version of S
Also called the minimal cover of S
Previous example:
S = {ABD, ABC, CD, BCD}
A minimal basis: {AB, AC, CD}
How simplified?
Four conditions.
Condition 1: Every FD in the minimal basis can be
derived from S, and vice versa.
33
Minimal Basis
Previous example:
S = {ABD, ABC, CD, BCD}
A minimal basis: {AB, AC, CD}
Condition 2: Every FD in the minimal basis is a
non‐trivial and decomposed FD.
Example in S: ABD does not satisfy this
condition
That is why ABD is not in the minimal basis
34
Minimal Basis
Previous example:
S = {ABD, ABC, CD, BCD}
A minimal basis: {AB, AC, CD}
Condition 3: No FD in the minimal basis is
redundant.
That is, no FD in the minimal basis can be derived
from the other FDs in the minimal basis.
Example in S: BCD can be derived from CD
That is why BCD is not in the minimal basis
35
Minimal Basis
Previous example:
S = {ABD, ABC, CD, BCD}
A minimal basis: {AB, AC, CD}
Condition 4: For each FD in the minimal basis, none of the attributes
on the left hand side is redundant
That is, if we remove an attribute from the left hand side, then the
resulting FD is a new FD that cannot be derived from the original set of
FDs
Example:
Consider ABC
If we remove B from the left hand side, we have AC
AC can be derived from S, since {A}+ = {ABDC} given S
This indicates that AC is “hidden” in S
There, we can add AC into S, without introducing extraneous information
Once AC is added, ABC becomes redundant and can be removed
Effectively, this indicates that B is redundant in ABC
This is why ABC is not in the minimal basis
36
Minimal Basis: Conditions
Let S be a set of FDs
Its minimal basis M is a set of FDs, such that
1. every FD in S can be derived from M, and vice versa
2. every FD in M is a non‐trivial and decomposed FD
3. if any FD is removed from M, then some FD in S
cannot be derived from M
4. for any FD in M, if we remove an attribute from its
left hand side, then the FD cannot be derived from S
37
Minimal Basis: Example
S = {AB, BC, AC}, M = {AB, BC}
M is a minimal basis of S
1. every FD in S can be derived from M, and vice versa
2. every FD in M is a non‐trivial and decomposed FD
3. if any FD is removed from M, then some FD in S
cannot be derived from M
4. for any FD in M, if we remove an attribute from its
left hand side, then the FD cannot be derived from S
38
Minimal Basis: Example 4
S = {AB, BC, AC}, M = {AB, ABC}
Is M a minimal basis of S?
1. every FD in S can be derived from M, and vice versa
2. every FD in M is a non‐trivial and decomposed FD
3. if any FD is removed from M, then some FD in S
cannot be derived from M
4. for any FD in M, if we remove an attribute from its
left hand side, then the FD cannot be derived from S
This condition is not satisfied
39
Minimal Basis: Example 2
S = {AB, BC, AC}, M = {ABC, BC}
Is M a minimal basis of S?
1. every FD in S can be derived from M, and vice versa
2. every FD in M is a non‐trivial and decomposed FD
3. if any FD is removed from M, then some FD in S
cannot be derived from M
4. for any FD in M, if we remove an attribute from its
left hand side, then the FD cannot be derived from S
This condition is not satisfied
40
Minimal Basis: Example 3
S = {AB, BC, AC}, M = {AB, BC, AC}
Is M a minimal basis of S? This condition is not satisfied
1. every FD in S can be derived from M, and vice versa
2. every FD in M is a non‐trivial and decomposed FD
3. if any FD is removed from M, then some FD in S
cannot be derived from M
4. for any FD in M, if we remove an attribute from its
left hand side, then the FD cannot be derived from S
41
Minimal Basis: Example 3
S = {AB, AC, CB}, M = {AB, ABC, CB}
Is M a minimal basis of S?
1. every FD in S can be derived from M, and vice versa
2. every FD in M is a non‐trivial and decomposed FD
3. if any FD is removed from M, then some FD in S
cannot be derived from M
4. for any FD in M, if we remove an attribute from its
left hand side, then the FD cannot be derived from S
43
Algorithm for Minimal Basis
Step 1: Transform the FDs, so that each right
hand side contains only one attribute
Step 2: Remove redundant attributes on the left
hand side of each FD
Step 3: Remove redundant FDs
44
Algorithm for Minimal Basis: Example
Given: a set S of FDs
Example: S = {ABD, ABC, CD, BCD}
Step 1: Transform the FDs, so that each right
hand side contains only one attribute
Result: S = {AB, AD, ABC, CD, BCD}
Reason:
Condition 2 for minimal basis:
Each FD is a non‐trivial and decomposed FD
45
Algorithm for Minimal Basis: Example
Result of the previous step:
S = {AB, AD, ABC, CD, BCD}
Step 2: Remove redundant attributes on the left hand side of
each FD
Both ABC and BCD have more than one attribute on the lhs
Let’s check ABC first
Is A redundant?
If we remove A, then ABC becomes BC
Whether this removal is OK depends on whether BC is implied
by S
If BC is implied by S, then the removal of A is OK, (since the removal
does not add extraneous information into S)
Is BC implied by S?
Check: Given S, we have {B}+ = {B}, which does NOT contain C
Therefore, BC is not implied by S, and hence, A is NOT
redundant
46
Algorithm for Minimal Basis: Example
Result of the previous step:
S = {AB, AD, ABC, CD, BCD}
Step 2: Remove redundant attributes on the left hand side of
each FD
Both ABC and BCD have more than one attribute on the lhs
Let’s check ABC first
Is B redundant?
If we remove B, then ABC becomes AC
Whether this is OK depends on whether AC is implied by S
Is AC implied by S?
Check: Given S, we have {A}+ = {ABCD}, which contains C
Therefore, AC is implied by S, and hence, B is redundant in
ABC
Thus, we can simplify ABC to AC
Result: S = {AB, AD, AC, CD, BCD}
47
Algorithm for Minimal Basis: Example
Result of the previous step:
S = {AB, AD, AC, CD, BCD}
Step 2: Remove redundant attributes on the left hand side of
each FD
Now let’s check BCD
Is B redundant?
If we remove B, then BCD becomes CD
Whether this is OK depends on whether CD is implied by S
Is CD implied by S?
Yes, it is explicitly in S already
Therefore, CD is implied by S, and hence, B is redundant
Thus, we can simplify BCC to CD
Result: S = {AB, AD, AC, CD}
Now there is no redundant attribute on the left hand side of any
FD
48
Algorithm for Minimal Basis: Example
Result of the previous step:
S = {AB, AD, AC, CD}
Step 3: Remove redundant FDs
Is AB redundant?
i.e., is AB implied by other FDs in S?
Let’s check
Without AB, we have {AD, AC, CD}
Given those FDs, we have {A}+ = {ACD}, which
does not contain B
Therefore, AB is not implied by the other FDs
49
Algorithm for Minimal Basis: Example
Result of the previous step:
S = {AB, AD, AC, CD}
Step 3: Remove redundant FDs
Is AD redundant?
i.e., is AD implied by other FDs in S?
Let’s check
Without AD, we have {AB, AC, CD}
Given those FDs, we have {A}+ = {ABCD}, which
contains D
Therefore, AD is implied by the other FDs
Hence, AD is redundant and should be removed
Result: S = {AB, AC, CD}
50
Algorithm for Minimal Basis: Example
Result of the previous step:
S = {AB, AC, CD}
Step 3: Remove redundant FDs
Is AC redundant?
i.e., is AC implied by other FDs in S?
Let’s check
Without AC, we have {AB, CD}
Given those FDs, we have {A}+ = {AB}, which does
not contain C
Therefore, AC is not implied by the other FDs
51
Algorithm for Minimal Basis: Example
Result of the previous step:
S = {AB, AC, CD}
Step 3: Remove redundant FDs
Is CD redundant?
i.e., is CD implied by other FDs in S?
Let’s check
Without CD, we have {AB, AC}
Given those FDs, we have {C}+ = {C}, which does not
contain D
Therefore, CD is not implied by the other FDs
Final minimal basis: {AB, AC, CD}
52
Algorithm for Minimal Basis: Example 2
Given: S = {BCDE, AE, DA, EB}
53
Algorithm for Minimal Basis: Example 2
Given: S = {BCDE, AE, DA, EB}
Step 1: Transform the FDs, so that each right
hand side contains only one attribute
Result: S = {BCD, BCE, AE, DA, EB}
Step 2: Remove redundant attributes on the left
hand side of each FD
Both BCD and BCE have more than one
attributes on the left hand side
54
Algorithm for Minimal Basis: Example 2
Result of the previous step:
S = {BCD, BCE, AE, DA, EB}
Step 2: Remove redundant attributes on the left hand
side of each FD
Let’s check BCD first
Is B redundant?
If we remove B, then BCD becomes CD
Whether this removal is OK depends on whether CD is
implied by S
Is CD implied by S?
Check: Given S, we have {C}+ = {C}, which does NOT
contain D
Therefore, CD is not implied by S, and hence, B is NOT
redundant
55
Algorithm for Minimal Basis: Example 2
Result of the previous step:
S = {BCD, BCE, AE, DA, EB}
Step 2: Remove redundant attributes on the left hand
side of each FD
Let’s check BCD first
Is C redundant?
If we remove C, then BCD becomes BD
Whether this removal is OK depends on whether BD is
implied by S
Is BD implied by S?
Check: Given S, we have {B}+ = {B}, which does NOT
contain D
Therefore, BD is not implied by S, and hence, C is NOT
redundant
56
Algorithm for Minimal Basis: Example 2
Result of the previous step:
S = {BCD, BCE, AE, DA, EB}
Step 2: Remove redundant attributes on the left hand
side of each FD
Now let’s check BCE
Is B redundant?
If we remove B, then BCE becomes CE
Whether this removal is OK depends on whether CE is
implied by S
Is CE implied by S?
Check: Given S, we have {C}+ = {C}, which does NOT
contain E
Therefore, CE is not implied by S, and hence, B is NOT
redundant
57
Algorithm for Minimal Basis: Example 2
Result of the previous step:
S = {BCD, BCE, AE, DA, EB}
Step 2: Remove redundant attributes on the left hand side of
each FD
Now let’s check BCE
Is C redundant?
If we remove C, then BCE becomes BE
Whether this removal is OK depends on whether BE is implied
by S
Is BE implied by S?
Check: Given S, we have {B}+ = {B}, which does NOT contain E
Therefore, BE is not implied by S, and hence, C is NOT
redundant
So there is no redundant attribute on the left hand side of any
FD
58
Algorithm for Minimal Basis: Example 2
Result of the previous step:
S = {BCD, BCE, AE, DA, EB}
Step 3: Remove redundant FDs
Is BCD redundant?
i.e., is BCD implied by other FDs in S?
Let’s check
Without BCD, we have {BCE, AE, DA, EB}
Given those FDs, we have {BC}+ = {BCE}, which does
not contain D
Therefore, BCD is not implied by the other FDs
59
Algorithm for Minimal Basis: Example 2
Result of the previous step:
S = {BCD, BCE, AE, DA, EB}
Step 3: Remove redundant FDs
Is BCE redundant?
i.e., is BCE implied by other FDs in S?
Let’s check
Without BCE, we have {BCD, AE, DA, EB}
Given those FDs, we have {BC}+ = {ABCDE}, which
contains E
Therefore, BCE is implied by the other FDs, and
can be removed
Result: S = {BCD, AE, DA, EB}
60
Algorithm for Minimal Basis: Example 2
Result of the previous step:
S = {BCD, AE, DA, EB}
Step 3: Remove redundant FDs
Is AE redundant?
i.e., is AE implied by other FDs in S?
Let’s check
Without AE, we have {BCD, DA, EB}
Given those FDs, we have {A}+ = {A}, which does
not contain E
Therefore, AE is not implied by the other FDs
61
Algorithm for Minimal Basis: Example 2
Result of the previous step:
S = {BCD, AE, DA, EB}
Step 3: Remove redundant FDs
Is DA redundant?
i.e., is DA implied by other FDs in S?
Let’s check
Without DA, we have {BCD, AE, EB}
Given those FDs, we have {D}+ = {D}, which does
not contain A
Therefore, DA is not implied by the other FDs
62
Algorithm for Minimal Basis: Example 2
Result of the previous step:
S = {BCD, AE, DA, EB}
Step 3: Remove redundant FDs
Is EB redundant?
i.e., is EB implied by other FDs in S?
Let’s check
Without EB, we have {BCD, AE, DA}
Given those FDs, we have {E}+ = {E}, which does not
contain B
Therefore, EB is not implied by the other FDs
So the final minimal basis is: {BCD, AE, DA,
EB}
63
Exercise
S = {AC, ACD, ADB}
1. Transform the FDs to ensure that the right hand
side of each FD has only one attribute
2. Check if we can remove any attribute from the
left hand side of any FD
3. See if any FD can be derived from the other FDs.
Remove those FDs one by one
64
Exercise
S = {AC, ACD, ADB}
1. Transform the FDs to ensure that the right hand
side of each FD has only one attribute
Result: S = {AC, ACD, ADB}
2. Check if we can remove any attribute from the
left hand side of any FD
Both ACD and ADD have more than one
attribute on the left hand side
Let's check ACD first
65
Exercise
Previous result: S = {AC, ACD, ADB}
2. Check if we can remove any attribute from the left
hand side of any FD
Let's check ACD first
Is A redundant?
If we remove A, then ACD becomes CD
Whether this removal is OK depends on whether CD is
implied by S
Is CD implied by S?
Check: Given S, we have {C}+ = {C}, which does NOT
contain D
Therefore, CD is not implied by S, and hence, A is NOT
redundant in ACD
66
Exercise
Previous result: S = {AC, ACD, ADB}
2. Check if we can remove any attribute from the left
hand side of any FD
Let's check ACD first
Is C redundant?
If we remove C, then ACD becomes AD
Whether this removal is OK depends on whether AD is
implied by S
Is AD implied by S?
Check: Given S, we have {A}+ = {ABCD}, which contain D
Therefore, AD is implied by S, and hence, we can
simplify ACD to AD
Result: S = {AC, AD, ADB}
67
Exercise
Previous result: S = {AC, AD, ADB}
2. Check if we can remove any attribute from the left
hand side of any FD
Now let's check ADB
Is A redundant?
If we remove A, then ADB becomes DB
Whether this removal is OK depends on whether DB is
implied by S
Is DB implied by S?
Check: Given S, we have {D}+ = {D}, which does NOT
contain B
Therefore, DB is not implied by S, and hence, A is NOT
redundant in ADB
68
Exercise
Previous result: S = {AC, AD, ADB}
2. Check if we can remove any attribute from the left
hand side of any FD
Now let's check ADB
Is D redundant?
If we remove D, then ADB becomes AB
Whether this removal is OK depends on whether AB is
implied by S
Is AB implied by S?
Check: Given S, we have {A}+ = {ABCD}, which contain B
Therefore, AB is implied by S, and hence, we can
simplify ADB to AB
Result: S = {AC, AD, AB}
69
Exercise
Previous result: S = {AC, AD, AB}
3. Remove redundant FDs
No FD is redundant
Final minimal basis: S = {AC, AD, AB}
70
3NF Decomposition
Input: A table R with a set of FDs
1. Find a minimal basis of the FDs
2. Combine the FDs whose left hand sides are the same
3. After that, for each FD, construct a table that contains all
attributes in the FD
4. Check if any of the tables contain a key for R; if not, then
create a table that contains a key for R
Example: R(A, B, C, D, E), with BCDE, AE, DA,
EB
Minimal basis: BCD, AE, DA, EB
No FDs can be combined
Corresponding tables: R1(B, C, D), R2(A, E), R3(A, D), R4(B, E)
Keys of R: AC, BC, CD, CE
R1 contains a key of R
71
3NF Decomposition
Input: A table R with a set of FDs
• Why do we need this step?
1. Find a minimal basis of the FDs
2. • To ensure lossless join decomposition
Combine the FDs whose left hand sides are the same
3. After that, for each FD, construct a table that contains all
attributes in the FD
4. Check if any of the tables contain a key for R; if not, then
create a table that contains a key for R
Example: R(A, B, C, D, E), with BCDE, AE, DA,
EB
Minimal basis: BCD, AE, DA, EB
No FDs can be combined
Corresponding tables: R1(B, C, D), R2(A, E), R3(A, D), R4(B, E)
Keys of R: AC, BC, CD, CE
R1 contains a key of R
72
3NF Decomposition: Adding Key for
Lossless Join
R(A, B, C, D), with AB, CD
Minimal basis: AB, CD
Corresponding tables: R1(A, B), R2(C, D)
Notice that R1 and R2 cannot be used to reconstruct R
This is why we require the following:
Check if any of the tables contain a key for R; if not, then
create a table that contains a key for R
In this case, R has only one key: AC
Therefore, we add a table R3(A, C)
73
Exercise: 3NF Decomposition
R(A, B, C, D, E), with AB, AC, BC, EC,
ED
1. Find a minimal basis of the FDs
2. Combine the FDs whose left hand sides are the same
3. After that, for each FD, construct a table that
contains all attributes in the FD
4. Check if any of the tables contain a key for R; if not,
then create a table that contains a key for R
74
Exercise: 3NF Decomposition
R(A, B, C, D, E), with AB, AC, BC, EC,
ED
Find a minimal basis
1. One attribute on the right: AB, AC, BC, EC,
ED
2. Remove redundant attributes on the left: AB,
AC, BC, EC, ED
3. Remove redundant FDs: AB, BC, EC, ED
75
Exercise: 3NF Decomposition
R(A, B, C, D, E), with AB, AC, BC, EC, ED
1. Minimal basis: AB, BC, EC, ED
Combine the FDs whose left hand sides are the same:
AB, BC, ECD
For each FD, construct a table that contains all attributes
in the FD:
R1(A, B), R2(B, C), R3(C, D, E)
Check if any of the tables contain a key for R; if not, then
create a table that contains a key for R:
Key for R is {AE}, which is not contained in R1, R2, or R3.
Create another table R4(A, E)
Final result: R1(A, B), R2(B, C), R3(C, D, E), R4(A, E)
76
Exercise 2: 3NF Decomposition
R(A, B, C, D, E), with AB, ABC, CDE, EC,
ED
1. Find a minimal basis of the FDs
2. Combine the FDs whose left hand sides are the same
3. After that, for each FD, construct a table that
contains all attributes in the FD
4. Check if any of the tables contain a key for R; if not,
then create a table that contains a key for R
77
Exercise 2: 3NF Decomposition
R(A, B, C, D, E), with AB, ABC, CDE, EC,
ED
Find a minimal basis
1. One attribute on the right: AB, ABC, CD, CE,
EC, ED
2. Remove redundant attributes on the left: AB,
AC, CD, CE, EC, ED
3. Remove redundant FDs: AB, AC, CD, CE,
EC
78
Exercise 2: 3NF Decomposition
R(A, B, C, D, E), with AB, ABC, CDE, EC,
ED
Minimal basis: AB, AC, CD, CE, EC
Combine the FDs whose left hand sides are the same:
ABC, CDE, EC
For each FD, construct a table that contains all attributes
in the FD:
R1(A, B, C), R2(C, D, E), R3(C, E)
Check if any of the tables contain a key for R; if not, then
create a table that contains a key for R:
Key for R is {A}, which is contained in R1
Final result: R1(A, B, C), R2(C, D, E), R3(C, E)
79
Summary
Poorly designed tables give rise to redundancy, update
anomalies, and deletion anomalies
BCNF eliminates these problems
BCNF: For any non‐trivial and decomposed FD on a table R, its
left hand side is a super‐key for R
But BCNF does not always preserve all FDs
We may need to perform a join of multiple tables to check
whether an FD holds
3NF: slightly weaker than BCNF; has update and deletion
anomalies in some rare cases, but preserves all FDs
3NF: For any non‐trivial and decomposed FD on a table R, either
its left hand side is a super‐key for R, or its right hand side is a
prime attribute
80
BCNF or 3NF?
BCNF is only inferior to 3NF in the sense that
sometimes it does not preserve all FDs
So, go for BCNF if we can find a BCNF
decomposition that preserves all FDs
If such a decomposition cannot be found
Go for BCNF if preserving all FDs is not important
Go for 3NF otherwise
81
Assignment 3
Will be announced this evening
10 multiple choice questions
Due on April 18, 11:59pm
82