7. Normalization
7. Normalization
Lecturer:
Kamruddin Md. Nur
Dept. of Computer Science
Stamford University Bangladesh
Dr. Kamruddin Nur
Normalization Block A
Room # 216
● Normalization
● Why Normalization
● Normal Forms
© Kamruddin Nur 2
Recap
The main objective of relational database is to create an accurate
representation of data, relationships between data, and constraints
© Kamruddin Nur 3
Normalization
“A technique to produce / design a set of relations that is optimal
from the point of view of database updating.”
© Kamruddin Nur 5
Data Redundancy
Major aim of relational database design is to group attributes
into relations to minimize data redundancy and reduce file
storage space required by base relations.
Problems associated with data redundancy are illustrated by
comparing the following Staff and Branch relations with the
StaffBranch
© Kamruddin Nur 6
Data Redundancy
© Kamruddin Nur 7
Data Redundancy
● StaffBranch relation has redundant data: details of a branch are
repeated for every member of staff.
© Kamruddin Nur 8
Update Anomalies
Relations that contain redundant information may potentially
suffer from update anomalies.
© Kamruddin Nur 9
Data Redundancy
© Kamruddin Nur 10
Insertion Anomalies
✔ New member of staff joins branch B005
● Insert new row into StaffBranch table
● Type wrong address: 163 Main St, Glasgow.
● Database is now inconsistent!
© Kamruddin Nur 12
Modification Anomalies
✔ Branch B003 has transferred to a new location
● New address is 145 Main St, Glasgow
● Must change three rows of the StaffBranch relation
© Kamruddin Nur 13
Functional Dependency
● Main concept associated with Normalization
● Describes relationships between attributes in a relation
● If A and B are attributes of relation R
if each value of A in R is associated with exactly one value of B in
R then A B
© Kamruddin Nur 14
Functional Dependency cont.
Let A, B, and C be subsets of the attributes of relation R.
Armstrong’s axioms are as follows:
1. Reflexivity
If B is a subset of A, then A B
2. Augmentation
If A B, then A,C C
3. Transitivity
If A B and B C, then A C
© Kamruddin Nur 15
Example: Functional Dependency
© Kamruddin Nur 16
Identifying Candidate Keys
✔ A candidate key is an attribute, or set of attributes, that uniquely
identifies a row
- Must be irreducible
- No part of a candidate can ever be NULL
© Kamruddin Nur 17
Identifying Primary Keys
✔ A primary key is a candidate key chosen to identify rows
uniquely within a table
- Other candidate keys called alternate keys
© Kamruddin Nur 18
Why Normalization?
✔ The main objective of relational database is to create an accurate
representation of data, its relationships and constraints.
© Kamruddin Nur 19
1st Normal Form
A relation in which intersection of each row and column contains
one and only one value.
How to achieve:
➔ if required break table into different entity table to minimize redundant
data (update anomalies).
© Kamruddin Nur 20
ONF to 1NF
© Kamruddin Nur 21
Problems with 1NF
INSERT anomalies:
Can not add a module with no texts
UPDATE anomalies:
To change lecturer for M1, we have
to change two rows
DELETE anomalies:
If we remove M3, we remove L2 as
well
© Kamruddin Nur 22
2nd Normal Form
A relation that is in 1st Normal Form and every non-primary-key
attribute is fully functionally dependent on the primary key.
How To Achieve:
➔ Break into tables by removing non-primary-attributes along with a
copy of part of primary key on which they are fully functionally
dependent.
➔ In other word, making attributes fully functional dependent on primary
keys.
© Kamruddin Nur 23
Finding Functional Dependencies (FD)
The primary key is {Module, Text}
so,
{Module, Text} {Dept, Lecturer}
{Module} {Dept}
{Module} {Lecturer}
{Lecturer} {Module}
But also,
{Module} {Dept, Lecturer}
© Kamruddin Nur 24
1NF to 2NF
© Kamruddin Nur 25
Problems Resolved in 2NF
Problems in 1NF: In 2NF:
the first two problems (INSERT
INSERT anomalies and UPDATE)are resolved but
Can not add a module with no texts not DELETE
UPDATE anomalies:
To change lecturer for M1, we have
to change two rows
DELETE anomalies:
If we remove M3, we remove L2 as
well
© Kamruddin Nur 26
3rd Normal Form
A relation which is in 1st and 2nd Normal Form, and in which no non-
primary-key attribute is transitively dependent on the primary key.
Transitive Dependency:
if A B, B C
Then A C
if and only if B A and C A
How To Achieve:
➔ In the above transitive dependency, A is not functionally dependent
on any of B or C
➔ Which means B or C are not a part of a relation which has attribute A.
➔ So create a table with B and C.
© Kamruddin Nur 27
2NF not In 3NF
2NFa is not in 3NF
Because,
{Module} {Lecturer}
{Lecturer} {Dept}
© Kamruddin Nur 28
2NF to 3NF
© Kamruddin Nur 29
Summary
© Kamruddin Nur 30