You are on page 1of 19

Database Normalization

Dr. RAVI VERMA


MCA, M.Tech, Phd (CSE)
Definition
• This is the process which allows you to winnow out redundant
data within your database.
• This involves restructuring the tables to successively meeting
higher forms of Normalization.
• A properly normalized database should have the following
characteristics
– Scalar values in each fields
– Absence of redundancy.
– Minimal use of null values.
– Minimal loss of information.
Levels of Normalization
• Levels of normalization based on the amount of
redundancy in the database.
• Various levels of normalization are:
– First Normal Form (1NF)
– Second Normal Form (2NF)

Number of Tables
Redundancy
– Third Normal Form (3NF)

Complexity
– Boyce-Codd Normal Form (BCNF)
– Fourth Normal Form (4NF)
– Fifth Normal Form (5NF)
– Domain Key Normal Form (DKNF)

Most
Mostdatabases
databasesshould
shouldbe
be3NF
3NFor
orBCNF
BCNFin inorder
orderto
toavoid
avoid
the
thedatabase
databaseanomalies.
anomalies.
DATABASE ANOMALIES

Database Anomalies can be categories in following way:-


• Insert Anomalies
• Delete Anomalies
• Update Anomalies

• All anomalies occurred due to redundancy and inconsistency


in database so that to eliminate all the anomalies issues we
need to use process of data Normalization.
Levels of Normalization

1NF
2NF
3NF
4NF
5NF
DKNF

Each
Eachhigher
higherlevel
levelisisaasubset
subsetof
ofthe
thelower
lowerlevel
level
First Normal Form (1NF)
A table is considered to be in 1NF if all the fields contain
only scalar values (as opposed to list of values).
Example (Not 1NF)

ISBN Title AuName AuPhone PubName PubPhone Price

0-321-32132-1 Balloon Sleepy, 321-321-1111, Small House 714-000-0000 $34.00


Snoopy, 232-234-1234,
Grumpy 665-235-6532

0-55-123456-9 Main Street Jones, 123-333-3333, Small House 714-000-0000 $22.95


Smith 654-223-3455
0-123-45678-0 Ulysses Joyce 666-666-6666 Alpha Press 999-999-9999 $34.00

1-22-233700-0 Visual Roman 444-444-4444 Big House 123-456-7890 $25.00


Basic

Author
Authorand
andAuPhone
AuPhonecolumns
columnsare
arenot
notscalar
scalar
1NF - Decomposition
1. Place all items that appear in the repeating group in a new table
2. Designate a primary key for each new table produced.
3. Duplicate in the new table the primary key of the table from
which the repeating group was extracted or vice versa.
Example (1NF)

ISBN AuName AuPhone

0-321-32132-1 Sleepy 321-321-1111

ISBN Title PubName PubPhone Price 0-321-32132-1 Snoopy 232-234-1234

0-321-32132-1 Balloon Small House 714-000-0000 $34.00 0-321-32132-1 Grumpy 665-235-6532

0-55-123456-9 Main Street Small House 714-000-0000 $22.95 0-55-123456-9 Jones 123-333-3333

0-123-45678-0 Ulysses Alpha Press 999-999-9999 $34.00 0-55-123456-9 Smith 654-223-3455

1-22-233700-0 Visual Big House 123-456-7890 $25.00 0-123-45678-0 Joyce 666-666-6666


Basic
1-22-233700-0 Roman 444-444-4444
Functional Dependencies
If one set of attributes in a table determines another set of
attributes in the table, then the second set of attributes is
said to be functionally dependent on the first set of
attributes.

Example 1

ISBN Title Price Table Scheme: {ISBN, Title, Price}


0-321-32132-1 Balloon $34.00 Functional Dependencies: {ISBN}  {Title}
0-55-123456-9 Main Street $22.95 {ISBN}  {Price}
0-123-45678-0 Ulysses $34.00

1-22-233700-0 Visual $25.00


Basic
Second Normal Form (2NF)
For a table to be in 2NF, there are two requirements
– The database is in first normal form
– All nonkey attributes in the table must be functionally dependent on
the entire primary key
Example 1 (Not 2NF)

Roll Name P_ID P_Name P_Details


101 A Cs101 Cargo Java

Scheme  {Roll, Name, P_ID, P_Name,P_Details}


1. Key (Roll, P_ID) {Name,P_ID,P_Name,P_Details}
2. {P_ID}  {P_Name, P_Details}
3. In this example Roll & P_ID is a composite Key attribute which hold
other remaining attributes but we can see P_Name & P_Detail
attributes are partially depends on P_ID which show partial
dependencies hence Relation not in 2NF.
2NF - Decomposition
Now to brings relation into 2NF we decompose the relation into 2NF
like below.
OLD Scheme  {Roll, Name, P_ID, P_Name, P_Details}
New Scheme1  {Roll, Name, P_ID}
New Scheme2  {P_ID, P_Name,P_Details}
1. Key (Roll) {Name,P_ID}
2. Key{P_ID}  {P_Name, P_Details}
3. In this example Roll no is a key attribute of New scheme 1 &
P_ID is only the Key attribute of New scheme 2 which hold other
remaining attributes so no partially dependency exist hence
Relation not in 2NF.

Roll Name P_ID P_ID P_Name P_Details


101 A CS101 CS101 A Java
Third Normal Form (3NF)
This form dictates that all non-key attributes of a table must be functionally
dependent on a candidate key i.e. there can be no interdependencies among
non-key attributes.

For a table to be in 3NF, there are two requirements


– The table should be second normal form
– No attribute is transitively dependent on the primary key

C_ID C_Name City Pin Salary


101 A Bhopal 462016 50K

Customer Scheme  {C_ID, C_Name, City, Pin, Salary}


1. Key (C_ID) {C_Name, City, Pin, Salary}
2. {Pin}  {City}
3. In this example C_ID is only the Key attribute which hold other
remaining attributes but we can see attribute city is also dependent on
Pin attribute, it shows attribute city is transitively dependence on
prime key attribute C_ID hence relation is not is 3NF.
3NF - Decomposition
1. Move all items involved in transitive dependencies to a new entity.
2. Identify a primary key for the new entity.
3. Place the primary key for the new entity as a foreign key on the
original entity.
Now to brings relation into 3NF we decompose the relation into 3NF like
below.
Old scheme {C_ID, C_Name, City, Pin, Salary}
New Scheme1  {C_ID, C_Name, Pin, Salary}
New Scheme2  {Pin, City}
1. Key (C_ID) {C_Name, Pin, Salary}
2. Key{Pin}  {City}
3. Now New scheme 1 & 2 both are in 3NF .

C_ID C_Name Pin Salary Pin City


101 A 462042 50K 462042 Bhopal
Boyce-Codd Normal Form (BCNF)
• BCNF is the advance version of 3NF. It is stricter than 3NF.
• A table is in BCNF if every functional dependency X → Y, X is the super key
of the table.
• For BCNF, the table should be in 3NF, and for every FD, LHS is super key.
• Example: Let's assume there is a company where employees work in more
than one department.
EMP_ID EMP_COUNTR EMP_DEPT DEPT_TYPE EMP_DEPT_NO
Y

264 India Designing D394 283

In the above table Functional dependencies are as follows:


EMP_ID  →  EMP_COUNTRY  
EMP_DEPT  →   {DEPT_TYPE, EMP_DEPT_NO}  
Candidate key: {EMP-ID, EMP-DEPT}
The table is not in BCNF because neither EMP_DEPT nor EMP_ID alone are keys.
Boyce Codd Normal Form (BCNF)
Decomposition
To convert the below table into BCNF, we decompose it into three tables:
EMP_ID EMP_COUNTRY EMP_DEPT DEPT_TYPE EMP_DEPT_NO

264 India Designing D394 283

EMP_ID EMP_CO EMP_DEPT_ DEPT_TYPE EMP_DEPT


UNTRY NO

264 India 283 D394 Designing

EMP_DEPT_MAPPING Table:

EMP_ID EMP_DEPT_
NO

Functional dependencies: 264 283

EMP_ID   →    EMP_COUNTRY  
EMP_DEPT_No   →   { EMP_DEPT, DEPT_TYPE}  
Candidate keys:
For the first table: EMP_ID
For the second table: EMP_DEPT
For the third table: {EMP_ID, EMP_DEPT}
Now, this is in BCNF because left side part of both the functional dependencies is a key.
Fourth Normal Form (4NF)
  • A relation will be in 4NF if it is in Boyce Codd normal form and has no multi-
valued dependency.
• For a dependency A → B, if for a single value of A, multiple values of B
exists, then the relation will be a multi-valued dependency.

Example (Not in 4NF)

 
STU_ID COURSE HOBBY

21 Computer Dancing

21 Math Singing

In the STUDENT relation is in 3NF, but a student with STU_ID, 21 contains two


courses, Computer and Math and two hobbies, Dancing and Singing. So there is a
Multi-valued dependency on STU_ID, which leads to unnecessary repetition of data.
Fourth Normal Form (4NF)
Decomposition
To bring the below table into 4NF, we can decompose it into two tables:
1. Move the two multi-valued relations to separate tables
2. Identify a primary key for each of the new entity.
STU_ID COURSE HOBBY

21 Computer Dancing

21 Math Singing

STUDENT_COURSE STUDENT_HOBBY

STU_ID HOBBY
STU_ID COURSE
21 Dancing
21 Computer
21 Singing
21 Math

Now both Students_Course & Student_Hobby relations are in 4NF.


Fifth Normal Form (5NF)
 
• Fifth normal form is satisfied when all tables are broken
into as many tables as possible in order to avoid
redundancy. Once it is in fifth normal form it cannot be
broken into smaller relations without changing the facts or
the meaning. 
Domain Key Normal Form (DKNF)
 
• The relation is in DKNF when there can be no insertion or
deletion anomalies in the database.
Thank you
• Please Question ?

You might also like