Normalization
Normalization
Database Management
System
Sushil Bhattarai
[email protected]
Normalization
• Main objective is to organize data in tables
• Helps maintain relations between tables
• One value should be at only one place
• Break down the data in smaller sizes
• See the following example of a table “Student” with following data
Name Address Subject Instructor
Ram Koteshwor Programming, Database Hari, Krishna
Shyam Baneshwor Database Krishna
Here, the Instructor is stored in multiple places. If the name of one of the
Instructors need to be changed, the data in multiple places needs to be changed.
If one of the students (say Shyam Prashad) decides to study a new subject, 2
columns (Subject and Instructor) need to be updated. The name of each of the
subject and Instructor appears multiple times in the table.
• Normal Forms:
1. 1 NF
2. 2 NF
3. 3 NF
1NF Rule
Each table cell should contain a single value
Each row must be unique.
The above table can be redesigned using 1NF as
Name Address Subject Instructor
Ram Koteshwor Programming Hari
Ram Koteshwor Database Krishna
Shyam Baneshwor Database Krishna
• Each cell now contains single value but still the data is repeated.
2NF rule
Subject
Student
StudentId Subject Instructor
Id Name Address
1 Programming Hari
1 Ram Koteshwor
1 Database Krishna
2 Shyam Baneshwor
2 Database Krishna
3NF rule
• Table should be in 2NF
• There should not be any transitive dependencies
Primary Key for
Student Table Primary Key for
Instructor Table
Student
Instructor
Id Name Address
Id Instructor
1 Ram Koteshwor
1 Hari
2 Shyam Baneshwor
2 Krishna
Primary Key for
Subject Table
All Columns are
dependent on Primary
Subject Key
Id Subject
1 Programming
2 Database
Detail
StudentId SubjectId InstructorId
1 1 1
1 2 2
2 2 2
Example of Normalization
• Consider the following data of different projects that has to be stored in a
table
Assets, Mutual
Fund,
Ram Finance 4.5, 3, 7
Profitability
Analysis
Break down the above data into appropriate tables using the 1,2 and 3 Normal Forms.
1NF
Project
Details
ID Employee DepartmentID
1 Ram 1 Department
2 Krishna 2
DepartmentID Department
1 Finance
2 R&D
Details
Project
EmployeeID ProjectID Time
ID Project
1 1 4.5
1 Assets 1 2 3
2 Mutual Fund 1 3 7
3 Profitability Analysis
2 4 8
4 Java 2 5 9
5 C++
Assignment of Normalization
• Consider the following data that has to be stored in a table
Name Salary Department Department_head Department_Location
ram, shyam, hari,krishna 8000, 1000, 9000,8000 IT Krishna Pokhara
kripa, sujan 8000, 9000 HR sujan kathmandu
Break down the above data into tables using 1NF, 2NF and 3NF.
The above data can be represented in 1NF as
Details