SQL Normalization
SQL Normalization
Ashish Zope
Data Engineer at Bajaj Finserv
What is Normalization?
➢ Normalization is the process of organizing the data in the
database.
➢ Normalization divides the larger table into smaller and links them
using relationships.
NORMAL
DESCRIPTION
FORM
1NF A relation is in 1NF if it contains an atomic value.
5NF A relation is in 5NF. If it is in 4NF and does not contain any join
dependency, joining should be lossless.
Advantages of Normalization
➢ You cannot start building the database before knowing what the
user needs.
➢ The performance degrades when normalizing the relations to
higher normal forms, i.e., 4NF, 5NF.
➢ It is very time-consuming and difficult to normalize relations of a
higher degree.
➢ Careless decomposition may lead to a bad database design,
leading to serious problems.
First Normal Form (1NF)
If a relation contains a composite or multi-valued attribute, it violates the first
normal form, or the relation is in the first normal form if it does not contain any
composite or multi-valued attribute.
EMPLOYEE table:
EmpID EmpName EmpMobNo State
1473 Ashish 7744046830 MH
7666556747
1323 Akshay 9767568976 MP
4545 Rahul 3444046830 GJ
2666556747
The decomposition of the EMPLOYEE table into 1NF has been shown below:
EMPLOYEE table:
EmpID EmpName EmpMobNo
1473 Ashish 7744046830
1473 Ashish 7666556747
1323 Akshay 9767568976
4545 Rahul 3444046830
4545 Rahul 2666556747
To convert the given table into 2NF, we decompose it into two tables:
EmployeeDetails Table
To convert the given table into 3NF, we decompose it into two tables:
➢ For BCNF, the table should be in 3NF, and for every FD, LHS is super
key.
Boyce Codd normal form (BCNF)
Example: Relation EMPLOYEE is not in 3NF because of multi-valued attribute EmpState
StateCode and EmpID, We can split the table into Employee Table and State Table and
Mapping of Employee Table and State Table
EmployeeDetails Table
EmpID EmpName EmpState StateCode
1473 Ashish MH 1
1323 Akshay MP 2
4545 Rahul GJ 3
5431 Ashwini MH 1
To convert the given table into BCNF, we decompose it into three tables:
➢ For 4NF, the table should be in BCNF, and for every multivalued
dependency, the left-hand side (LHS) must be a superkey
Fourth normal form (4NF)
Example: we have a table named EmployeeDetails that contains information about
employees, their skills, and hobbies:
EmployeesDetails Table
EmpID EmpName Skills Hobbies
1 Ashish SQL Photography
1 Ashish PySpark Photography
2 Akshay PowerBI Biking
2 Akshay PowerBI Painting
3 Rahul Python Reading
3 Rahul JAVA Reading
By splitting the original table into these three tables, we eliminate the multi-valued
dependencies, and each table now represents a single entity.
Employees Table EmployeeSkills Table EmployeeHobbies Table
➢ A table is in 5NF if it is in 4NF and does not contain any non-trivial join
dependencies.
➢ For 5NF, the table should be in 4NF, and for every join dependency,
the left-hand side (LHS) must be a superkey1
Ashish Zope
THANK YOU Data Engineer at Bajaj Finserv
If you find this helpful, Repost and follow for more content.
Submit corrections in comments, if any.