0% found this document useful (0 votes)
4 views

Normalization in DBMS

Normalization in DBMS is a process aimed at organizing data to prevent anomalies such as insertion, update, and deletion. The document explains the four normal forms: First Normal Form (1NF), Second Normal Form (2NF), Third Normal Form (3NF), and Boyce-Codd Normal Form (BCNF), detailing their definitions and examples. Each normal form addresses specific types of data redundancy and dependency issues to ensure a more efficient database structure.

Uploaded by

opilionobert
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Normalization in DBMS

Normalization in DBMS is a process aimed at organizing data to prevent anomalies such as insertion, update, and deletion. The document explains the four normal forms: First Normal Form (1NF), Second Normal Form (2NF), Third Normal Form (3NF), and Boyce-Codd Normal Form (BCNF), detailing their definitions and examples. Each normal form addresses specific types of data redundancy and dependency issues to ensure a more efficient database structure.

Uploaded by

opilionobert
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Normalization in DBMS: 1NF, 2NF,

3NF and BCNF in Database


LAST UPDATED: MAY 5, 2022 BY CHAITANYA SINGH | FILED UNDER: DBMS

Normalization is a process of organizing the data in database to


avoid data redundancy, insertion anomaly, update anomaly & deletion
anomaly. Let’s discuss about anomalies first then we will discuss
normal forms with examples.

Anomalies in DBMS
There are three types of anomalies that occur when the database
is not normalized. These are: Insertion, update and deletion
anomaly. Let’s take an example to understand this.

Example: A manufacturing company stores the employee details in a


table Employee that has four attributes: Emp_Id for storing employee’s
id, Emp_Name for storing employee’s name, Emp_Address for storing
employee’s address and Emp_Dept for storing the department details in
which the employee works. At some point of time the table looks like
this:

Emp_Id Emp_Name Emp_Address Emp_Dept

101 Rick Delhi D001

101 Rick Delhi D002

123 Maggie Agra D890


166 Glenn Chennai D900

166 Glenn Chennai D004

This table is not normalized. We will see the problems that we face
when a table in database is not normalized.

Update anomaly: In the above table we have two rows for


employee Rick as he belongs to two departments of the company. If we
want to update the address of Rick then we have to update the same in
two rows or the data will become inconsistent. If somehow, the correct
address gets updated in one department but not in other then as per
the database, Rick would be having two different addresses, which is
not correct and would lead to inconsistent data.

Insert anomaly: Suppose a new employee joins the company, who is


under training and currently not assigned to any department then we
would not be able to insert the data into the table if Emp_Dept field
doesn’t allow null.

Delete anomaly: Let’s say in future, company closes the


department D890 then deleting the rows that are having Emp_Dept as
D890 would also delete the information of employee Maggie since she is
assigned only to this department.

To overcome these anomalies we need to normalize the data. In


the next section we will discuss about normalization.

Normalization
Here are the most commonly used normal forms:
 First normal form(1NF)
 Second normal form(2NF)
 Third normal form(3NF)
 Boyce & Codd normal form (BCNF)

First normal form (1NF)


A relation is said to be in 1NF (first normal form), if it doesn’t
contain any multi-valued attribute. In other words you can say that a
relation is in 1NF if each attribute contains only atomic(single) value
only.

As per the rule of first normal form, an attribute (column) of a table


cannot hold multiple values. It should hold only atomic values.

Example: Let’s say a company wants to store the names and contact
details of its employees. It creates a table in the database that looks
like this:

Emp_Id Emp_Name Emp_Address Emp_Mobile

101 Herschel New Delhi 8912312390

8812121212 ,
102 Jon Kanpur
9900012222

103 Ron Chennai 7778881212

104 Lester Bangalore 9990000123,


8123450987

Two employees (Jon & Lester) have two mobile numbers that caused
the Emp_Mobile field to have multiple values for these two employees.

This table is not in 1NF as the rule says “each attribute of a table
must have atomic (single) values”, the Emp_Mobile values for
employees Jon & Lester violates that rule.

To make the table complies with 1NF we need to create separate rows
for the each mobile number in such a way so that none of the
attributes contains multiple values.

Emp_Id Emp_Name Emp_Address Emp_Mobile

101 Herschel New Delhi 8912312390

102 Jon Kanpur 8812121212

102 Jon Kanpur 9900012222

103 Ron Chennai 7778881212

104 Lester Bangalore 9990000123


104 Lester Bangalore 8123450987

To learn more about 1NF refer this article: 1NF

Second normal form (2NF)


A table is said to be in 2NF if both the following conditions hold:

 Table is in 1NF (First normal form)


 No non-prime attribute is dependent on the proper subset of
any candidate key of table.

An attribute that is not part of any candidate key is known as


non-prime attribute.

Example: Let’s say a school wants to store the data of teachers and
the subjects they teach. They create a table Teacher that looks like this:
Since a teacher can teach more than one subjects, the table can have
multiple rows for a same teacher.

Teacher_Id Subject Teacher_Age

111 Maths 38

111 Physics 38
222 Biology 38

333 Physics 40

333 Chemistry 40

Candidate Keys: {Teacher_Id, Subject}


Non prime attribute: Teacher_Age

This table is in 1 NF because each attribute has atomic values.


However, it is not in 2NF because non prime attribute Teacher_Age is
dependent on Teacher_Id alone which is a proper subset of candidate
key. This violates the rule for 2NF as the rule says “no non-prime
attribute is dependent on the proper subset of any candidate
key of the table”.

To make the table complies with 2NF we can disintegrate it in two


tables like this:
Teacher_Details table:

Teacher_Id Teacher_Age

111 38

222 38
40

333

Teacher_Subject table:

Teacher_Id Subject

111 Maths

111 Physics

222 Biology

333 Physics

333 Chemistry
Now the tables are in Second normal form (2NF). To learn more about
2NF refer this guide: 2NF

Third Normal form (3NF)


A table design is said to be in 3NF if both the following conditions hold:

 Table must be in 2NF


 Transitive functional dependency of non-prime attribute
on any super key should be removed.

An attribute that is not part of any candidate key is known as non-


prime attribute.

In other words 3NF can be explained like this: A table is in 3NF if it is in


2NF and for each functional dependency X-> Y at least one of the
following conditions hold:

 X is a super key of table


 Y is a prime attribute of table

An attribute that is a part of one of the candidate keys is known as


prime attribute.

Example: Let’s say a company wants to store the complete address of


each employee, they create a table named Employee_Details that looks
like this:

Emp_Id Emp_Name Emp_Zip Emp_State Emp_City Emp_District

1001 John 282005 UP Agra Dayal Bagh


1002 Ajeet 222008 TN Chennai M-City

1006 Lora 282007 TN Chennai Urrapakkam

1101 Lilly 292008 UK Pauri Bhagwan

1201 Steve 222999 MP Gwalior Ratan

Super keys: {Emp_Id}, {Emp_Id, Emp_Name}, {Emp_Id, Emp_Name, Emp_Zip}…so


on
Candidate Keys: {Emp_Id}
Non-prime attributes: all attributes except Emp_Id are non-prime as
they are not part of any candidate keys.

Here, Emp_State, Emp_City & Emp_District dependent on Emp_Zip.


Further Emp_zip is dependent on Emp_Id that makes non-prime attributes
(Emp_State, Emp_City & Emp_District) transitively dependent on super key
(Emp_Id). This violates the rule of 3NF.

To make this table complies with 3NF we have to disintegrate the table
into two tables to remove the transitive dependency:
Employee Table:

Emp_Id Emp_Name Emp_Zip

1001 John 282005

1002 Ajeet 222008

1006 Lora 282007

1101 Lilly 292008

1201 Steve 222999

Employee_Zip table:

Emp_Zip Emp_State Emp_City Emp_District


282005 UP Agra Dayal Bagh

222008 TN Chennai M-City

282007 TN Chennai Urrapakkam

292008 UK Pauri Bhagwan

222999 MP Gwalior Ratan

You might also like