What is normalization

Posted By : Bipul Kumar Tiwari,

Database Normalisation is a technique of organizing the data in the database. Normalization is the process of removing redundant data from your tables in order to improve storage efficiency, data integrity and scalability.
There are several benefits for using Normalization in Database.

A.  Eliminate data redundancy.
B.  Improve performance.
C.  Query optimization.
D.  Faster update due to less number of columns in one table.
E.  Index improvement.

Normalization Rule:

Normalization rule are divided into following normal form.
1.  First Normal Form
2.  Second Normal Form
3.  Third Normal Form
4.  BCNF
5.  fourth normal form
6.  Fifth normal form

1. 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 Learning Point wants to store the names and contact details of its Students. It creates a table that looks like this:


Roll_No Stud_Name Stud_Address Mob_No
101 Priyanka Tiwari New Delhi 1236547891
102 Pragati Tiwari Noida 6547896541
3571598524
103 Manish Singh Bangalore 897654652
104 Priyul Priya Bangalore 5643217895
9685741452

Note: Two Students (Pragati Tiwari & Priyul Priya) are having two mobile numbers so the Learning point 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 Mob_no values for students Pragati Tiwari & Priyul Priya violates that rule.

To make the table Students with 1NF we should have the data like this:


Roll_No Stud_Name Stud_Address Mob_No
101 Priyanka Tiwari New Delhi 1236547891
102 Pragati Tiwari Noida 6547896541
102 Pragati Tiwari Noida 3571598524
103 Manish Singh Bangalore 897654652
104 Priyul Priya Bangalore 5643217895
104 Priyul Priya Bangalore 9685741452

2. 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.

Prime attribute:

An attribute, which is a part of the prime-key(any candidate key ), is known as a prime attribute.

Non-prime attribute:

An attribute, which is not a part of the prime-key (any candidate key ), is said to be a non-prime attribute. Example: Suppose Learning Point wants to store the data of faculty and the subjects they teach. They create a table that looks like this: Since a faculty can teach more than one subjects, the table can have multiple rows for a same faculty.

Faculty_ID Subject Faculty_age
101 Maths 31
101 Programming in c 31
102 RDBMS 33
103 Organizational Behaviour 32
104 Maths 32
104 Dot net 32


Prime attribute(Candidate Keys): {Faculty_ID, subject}
Non prime attribute: {Faculty_age}

The table is in 1 NF because each attribute has atomic values. However, it is not in 2NF because non prime attribute Faculty_age is dependent on Faculty_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 break it in two tables like this:


tblFaculty_details table:

Faculty_ID Faculty_age
101 31
101 31
102 33
103 32
104 32
104 32

tblFaculty_subject table:

Faculty_ID Subject
101 Maths
101 Programming in c
102 RDBMS
103 Organizational Behaviour
104 Maths
104 Dot net

Now the tables comply with Second normal form (2NF).

3. Third Normal form (3NF)

A table design is said to be in 3NF if both the following conditions hold:
*  Table must be in Second normal form (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: Suppose 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_City Emp_District Emp_State Emp_zip
101 Priyanka Tiwari Mayur Vihar Mayur Vihar New Delhi 110096
102 Priyul Priya Gurugram Gurugram HR 430200
103 Viaksh Singh Noida Noida UP 110096
104 Manish Singh Varanshi Varanshi UP 123654
105 L B Tiwari Sikandarpur Ballia UP 277303

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. And, 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 break the table into two tables to remove the transitive dependency:
TblEmployee table:

Emp_ID Emp_Name Emp_zip
101 Priyanka Tiwari 110096
102 Priyul Priya 430200
103 Viaksh Singh 110096
104 Manish Singh 123654
105 L B Tiwari 277303

TblEmployee_zip table:

Emp_zip Emp_City Emp_District Emp_State
110096 Mayur Vihar Mayur Vihar New Delhi
430200 Gurugram Gurugram HR
110096 Noida Noida UP
123654 Varanshi Varanshi UP
277303 Sikandarpur Ballia UP

Now the tables comply with Third Normal form (3NF).

3. Boyce Codd normal form (BCNF)

It is an advance version of 3NF that’s why it is also referred as 3.5NF. BCNF is stricter than 3NF. A table complies with BCNF if it is in 3NF and for every functional dependency X->Y, X should be the super key of the table.

Example: Suppose there is a company wherein employees work in more than one department. They store the data like this:

Emp_id Emp_nationality Emp_dept dept_type dept_no_of_emp
1001 India Production and planning D001 250
1001 India stores D001 200
1002 US design and technical support D134 100
1002 US Purchasing department D134 300

Functional dependencies in the table above:
emp_id -> emp_nationality
emp_dept -> {dept_type, dept_no_of_emp}

Candidate key: {emp_id, emp_dept}

The table is not in BCNF as neither emp_id nor emp_dept alone are keys.
To make the table comply with BCNF we can break the table in three tables like this:

emp_nationality table:
Emp_id Emp_nationality
1001 India
1002 US

emp_dept table:
Emp_dept dept_type dept_no_of_emp
Production and planning D001 250
stores D001 200
design and technical support D134 100
Purchasing department D134 300

emp_dept_mapping table:
Emp_id Emp_dept
1001 Production and planning
1001 stores
1002 design and technical support
1002 Purchasing department

Functional dependencies:
emp_id -> emp_nationality
emp_dept -> {dept_type, dept_no_of_emp}

Candidate keys:
For first table: emp_id
For second table: emp_dept
For third table: {emp_id, emp_dept}

This is now in BCNF as in both the functional dependencies left side part is a key.

Related Articles

 

About the Author

author
Its me BIPUL who is logically minded creative at heart , a good communicator , a self taught full stack developer. I constantly focuses on my thinking , reading , collecting and creating my work in a order to enhance my skills.

I discover new dimensions for growing bussiness with a proven record in creating database and programming. I have a strong technical skills as well as strong interpersonal skills. Read more...
 

Browse By Category

Popular Articles