You are on page 1of 16

What is normalization?

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

 Update anomalies − If data items are scattered and are not linked to each other properly, then it could lead to
strange situations. For example, when we try to update one data item having its copies scattered over several
places, a few instances get updated properly while a few others are left with old values. Such instances leave the
database in an inconsistent state.

 Deletion anomalies − We tried to delete a record, but parts of it was left undeleted because of unawareness, the
data is also saved somewhere else.

 Insert anomalies − We tried to insert data in a record that does not exist at all.

Normalization is a method to remove all these anomalies and bring the database to a consistent state.
Anomalies in DBMS cont….

The above table is not normalized. We will see the problems that we face when a table is not normalized.
Types of normalization
Here are the most commonly used normal forms:
• First normal form(1NF)
• Second normal form(2NF)
• Third normal form(3NF)
First normal form (1NF)

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: Suppose a company wants to store the names and contact


details of its employees. It creates a table that looks like this:
Two employees (Jon & Lester) are having two mobile numbers so the company stored them in the same field as you
can see in the table above.
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 should have the data like this:
Second normal form (2NF)

A database is in second normal form if it satisfies the following


conditions:
• It is in first normal form
• Eliminates the Partial Dependency
• Partial Dependency occurs when a non-prime attribute is
functionally dependent on part of a candidate key.
Consider the following example:

This table has a composite primary key [Customer ID, Store ID]. The non prime attribute is
[Purchase Location]. In this case, [Purchase Location] only depends on [Store ID], which is
only part of the primary key. Therefore, this table does not satisfy second normal form.

This is called partial dependency, which is not allowed in Second Normal Form.


To bring this table to second normal form, we break the table into two tables, and now we have the
following:
Third normal form (3NF)

For a table to be in the third normal form, It should be in the Second Normal form.

And it should not have Transitive Dependency.

A transitive dependency occurs when one non-prime attribute is dependent on another non-


prime attribute.
Example

With exam_name and total_marks added to our Score table, it saves more data now. Primary
key for our Score table is a composite key, which means it's made up of two attributes or
columns → student_id + subject_id. Our new column exam_name depends on both student and
subject.And what about our second new column total_marks? Does it depend on our Score
table's primary key?
Well, the column total_marks depends on exam_name as with exam type the total score
changesBut, exam_name is just another column in the score table. It is not a primary key or
even a part of the primary key, and total_marks depends on it.This is Transitive Dependency.
When a non-prime attribute depends on other non-prime attributes rather than depending upon
the prime attributes or primary key.
How to remove Transitive Dependency
Again the solution is very simple. Take out the columns exam_name and total_marks from
Score table and put them in an Exam table and use the exam_id wherever required.
Advantage of removing Transitive Dependency

The advantage of removing transitive dependency is,


• Amount of data duplication is reduced.
• Data integrity achieved.

You might also like