DBMS 13-16
DBMS 13-16
1
2/12/2025
Normalization
Normalization is a systematic approach to organize data in a
database to eliminate redundancy, avoid anomalies and ensure data
consistency.
• Normal Forms:
• 1NF 1NF
• 2NF 2NF
• 3NF 3NF
• BCNF
BCNF
2
2/12/2025
Un-Normalized
3
2/12/2025
4
2/12/2025
5
2/12/2025
6
2/12/2025
CID CName
CS101 DBMS
EID SID SName CID CName
CS102 C++
1 101 Vineet CS101 DBMS
CS103 Micro
2 101 Vineet CS103 Micro
3 102 Ayush CS102 C++
SID SName
4 102 Ayush CS101 DBMS
101 Vineet
5 103 Surya CS103 Micro
102 Ayush
6 103 Surya CS102 C++ EID SID CID
103 Surya
1 101 CS101
2 101 CS103
3 102 CS102
4 102 CS101
5 103 CS103
6 103 CS102
Department of CSE, National Institute of Technology Rourkela
7
2/12/2025
8
2/12/2025
9
2/12/2025
10
2/12/2025
11
2/12/2025
Candidate Keys:
• AC
Non-Prime Attributes:
• B,D,E,F,G,H
Partial Dependency:
• AB, CDE
Decomposition
• One table for AB,
• Another table for CDE
• And the main table.
12
2/12/2025
Normalization Example: 1
• Is the given relation is in 1NF?
• Is the given relation is in 2NF?
Normalization Example: 1
• Is the table is redundant?
13
2/12/2025
Example 2
IF R(A, B, C) A B C
• BC a 1 x
• Is the table is in 1NF? b 2 y
a 3 z
• Is the table is in 2NF?
c 3 z
• Candidate Key: AB
d 3 z
• Prime Attribute: A, B e 3 z
• Non-Prime Attribute: C
• Is there any partial dependencies exist?
Example 2
IF R(A, B, C)
• BC
• How we can Normalize the table into 2NF.
A B C A B
a 1 x a 1 B C
b 2 y b 2 1 x
a 3 z a 3 2 y
c 3 z c 3 3 z
d 3 z d 3
e 3 z e 3
14
2/12/2025
15
2/12/2025
16
2/12/2025
Normalization Example: 1
• What are the transitive dependency in this table?
• SID SName : Why? SID is part of composite key, but not the both
attributes?
• CID CName, Prof. : Same as above.
Normalization Example: 1
• How it will be converted o 3NF?
SID SName CID CName Prof.
101 Vineet CS101 DBMS DNY
101 Vineet CS102 Algo SP
102 Ayush CS101 DBMS DNY
102 Ayush CS103 Python PD
17
2/12/2025
Normalization Example: 1
• R (A, B, C, D)
• AB CD, DA
18
2/12/2025
BCNF
Candidate Key: {SID}, {VID}
FD = {SID SName, SID VID, VID age, VID SID}
Check for the condition: For each FD, LHS should be Super Key
or Candidate Key.
SID SName VID Age
101 Ravi V01 20
102 Varun V02 19
103 Ravi V03 21
104 Rahul V04 22
BCNF Example
• R (A, B, C, D)
• AB CD, DA
19
2/12/2025
BCNF Example 2
• R (A, B, C)
• AB C, CB
Question
Q1. R(A< B, C, D, E, F, G, H, I ,J); FD {ABC, ADE, BF, FGH,
DIJ }
• Keys?
• Decompose it to 2NF
20
2/12/2025
Decomposition Rule
Decomposition should be lossless: (No data loss: fulfilled by 1NF,
2NF, 3NF, BCNF)
Dependency should be preserved (Sometime not fulfilled by
BCNF).
Decomposition Example
• R (A, B, C, D)
• AB CD, DA
21
2/12/2025
Questions
When we can conclude that the relation is in 1NF?
How to convert a relation into 1NF?
When we can conclude that any relation is in 2NF?
What is partial dependency?
How to convert a relation into 2NF?
When we can conclude that the relation is in 3NF?
What is transitive dependency?
When to say that the relation is in BCNF?
What is non-trivial dependency?
Consider a relation R(A, B, C, D), the primary kay for the relation
is {AB}, is that possible that value of A or B can be null?
Questions
The first reason we have already discussed (we will have many
redundant data which can cause Anamolies)
It is possible that the dependency given for the relation may not
hold for some instances.
Consider a relation R(A, B, C, D) and FD = {AB D, BC}
The candidate key for this relation is AB, the same will be primary
key.
The only condition for primary key is it should be unique.
Thus the value of either A or B can be null, If the value of B is null
the dependency BC will be void.
22
2/12/2025
Questions
Consider a relation R(A, B, C, D) and FD = {AB C, CD}
What will be candidate key and primary key for the relation?
Is the relation is in 2NF or not?
Is the relation is in 3NF?
What about BCNF?
What is the problem if the relation is not in 3NF?
• Again for the first dependency AB C; AB combined is a primary
key at least one of them will be not null; thus for sure this
dependency will hold.
• But what about CD; C may become null, and thus AB may not
reach to D.
• R1(A, B, C) & R2(C, D)
Questions
Consider a relation R(A, B, C, D, E) and FD = {A C, BE
CD}
What will be candidate key and primary key for the relation?
Is the relation is in 2NF or not?
Is the relation is in 3NF?
What about BCNF?
How many relations we will get after converting this relation to
3NF?
23
2/12/2025
Questions
Consider a relation R(A, B, C) and FD = {AB C, CB}
What will be candidate key and primary key for the relation?
Is the relation is in 2NF?
Is the relation is in 3NF?
Is the relation is in BCNF?
Relations after decomposition?
Questions
If you are asked to identify NF of a relation then from which NF
(1NF, 2NF, 3NF, BCNF) will you start and why?
Identify normal forms for this relations.
R(ABCEFGH), FD = {ABC, ADE, BF, FGH}
• 1NF
R(ABCDEF), FD = {ABC, DCAE, EF}
• 1NF
R(ABCDEF), FD = {ABC, DCAE, EF}
• 1NF
R (ABCDEFGHI), FD = {AB C, BDEF, AD GH, AI}
• 1NF
R (ABCDE), FD = {ABCD, DA, BCDE}
• 3NF
24
2/12/2025
Questions
Identify normal forms for this relations.
R (ABCDE), FD = {BCADE, DB}
• 3NF
R(VWXYZ), FD = {XYV, YZ, ZY, VWX}
• 1NF
R(ABCDEF), FD = {ABCD, ABDE, CD F, CDF B, BF
D}
• 1NF
R(ABC), FD = {AB, BC, CA} [GATE]
• BCNF
GATE Questions
25
2/12/2025
26
2/12/2025
27
2/12/2025
28
2/12/2025
29
2/12/2025
30
2/12/2025
31
2/12/2025
32
2/12/2025
33
2/12/2025
Decomposition
Decomposition
Normalization: decomposition of tables in smaller table.
Rule-1 (Mandatory): Decomposition should be Lossless.
• Lossless: if we combine the child table we must get parent table.
• Lossy: if we do not get the parent table (actual tuple) then lossy.
• Problem with lossy decomposition: (a) we may not get original tuple.
(b) We may get redundant tuple.
34
2/12/2025
Lossless Decomposition
If a relation R is decomposed into two relations R1 and R2, then
the decomposition will be lossless iff:
a. Attribute(R1) ∪ Attribute(R2) = Attribute (R) An attribute must
be present in at least one table.
b. Attribute(R1) ∩ Attribute (R2) != Ø There must be a common
attribute between the decomposed relations.
c. Attribute(R1) ∩ Attribute(R2) Attribute (R1) or Attribute (R1)
∩ Attribute (R2) Attribute (R2) the common attribute must
be a candidate key in one of the decomposed relation.
Decomposition
Condition (a): Attribute(R1) ∪ Attribute(R2) = Attribute (R)
An attribute must be present in at least one table.
35
2/12/2025
Decomposition
Condition (b): Attribute(R1) ∩ Attribute (R2) != Ø There
must be at least one common attribute between the decomposed
relations.
Query: find the value of C if the value of a is 1.
We cannot write an equivalent query for this as there is no
common attribute for checking.
A B
1 2
2 2
A B C D 3 3
1 2 1 X
2 2 2 Y
3 3 2 Z C D
1 X
2 Y
2 Z
Decomposition
Condition (b): Attribute(R1) ∩ Attribute (R2) != Ø There
must be at least one common attribute between the decomposed
relations.
Query: find the value of C if the value of a is 1.
Select R2.C from R2 Natural Join Where R1.A = 1.
A B
A B B C
1 2
1 2 2 1
A B C 2 2
1 2 2 2
A B C 3 3
1 2 3 2 1 2 1
1 2 1
2 2 2 1 1 2 2
2 2 2
2 2 2 2 2 2 1
3 3 2 B C
2 2 3 2 2 2 2
2 1
3 3 2 1 3 3 2
2 2
3 3 2 2 3 2
3 3 3 2
36
2/12/2025
Decomposition
Condition (c): Attribute(R1) ∩ Attribute(R2) Attribute (R1) or
Attribute (R1) ∩ Attribute (R2) Attribute (R2) the common
attribute must be a candidate key in one of the decomposed
relation.
Query: find the value of C if the value of a is 1.
Select R2.C from R2 Natural Join Where R1.A = 1.
A B A C A B
1 2 1 1 1 2
1 2 2 2 A B C 2 2
A B C 3 3
1 2 3 2 1 2 1
1 2 1
2 2 1 1 2 2 2
2 2 2
2 2 2 2 3 3 2
3 3 2 A C
2 2 3 2
1 1
3 3 1 1
2 2
3 3 2 2
3 2
3 3 3 2
Department of CSE, National Institute of Technology Rourkela
37
2/12/2025
38
2/12/2025
Dependency Preservation
R(ABC) F ={ABCD, DA)}
• R1(A, D) R2(B,C,D)
• F1(AD) F2(BDC)
39
2/12/2025
40
2/12/2025
4 NF
The relation should be in BCNF and it should not have multi-
valued dependency.
A B C D
1 X P 2
1 Y Q 3
1 X P 3
41
2/12/2025
4 NF
Now check for BCNF
Candidate key ABD
Dependency BC Note allowed.
Decompose it to two tables R1 (ABD), R2 (BC)
Now the relation is in BCNF. A B D
1 X 2
1 Y 3
A B C D
1 X 2
1 X P 2
1 Y Q 3
1 X P 3 B C
X P
Y Q
4 NF
Multivalued Dependency ()
AB
AD
Decompose the first relation to tow more relations R1’(AB),
R1’’(AD) A B
1 X
1 Y
A B D
1 X 2
A D
1 Y 3
A B C D 1 2
1 X 3
1 X P 2 1 3
1 Y Q 3
1 X P 3 B C
X P
Y Q
42
2/12/2025
5 NF
The relation should be in 4NF, and the decomposition should be
lossless.
Also known as Project-Join Normal Form (PJNF)
We already discussed this concept yesterday.
Normalization Summary
Summary of Normal Forms:
43
2/12/2025
44
2/12/2025
45
2/12/2025
46
2/12/2025
47
2/12/2025
48
2/12/2025
49