Monday, April 11, 2022

Database Normalization with Example

 

Database Normal Forms :

Database Normalization: Normalization is the process of splitting or organizing data to reduce redundancy and avoid data anomalies.

Here is a list of Normal Forms in SQL:

  • 1NF (First Normal Form)
  • 2NF (Second Normal Form)
  • 3NF (Third Normal Form)
  • BCNF (Boyce-Codd Normal Form)
  • 4NF (Fourth Normal Form)
  • 5NF (Fifth Normal Form)
  • 6NF (Sixth Normal Form)

However, in most practical applications, normalization achieves its best in the 3rd Normal Form. The evolution of Normalization in SQL theories is illustrated below-

Database Normal Forms
Database Normal Forms

Database Normalization With Examples

Database Normalization Example can be easily understood with the help of a case study. Assume a video library maintains a database of movies rented out. Without any normalization in the database, all information is stored in one table, as shown below. Let’s understand the Normalization database with a normalization example with a solution:

Database Normalization With Example

Here you see the Movies Rented column has multiple values. Now let’s move into 1st Normal Forms:


1NF (First Normal Form) Rules: No multivalue attribute.

  • Each table cell should contain a single value.
  • Each record needs to be unique.

The above table in 1NF-

1NF Example :

Example of 1NF in DBMS

Example of 1NF in DBMS


2NF (Second Normal Form) Rules :

  • Rule 1- Be in 1NF
  • Rule 2- Single Column Primary Key that does not functionally dependent on any subset of candidate key relation

It is clear that we can’t move forward to make our simple database in 2nd Normalization form unless we partition the table above.


2NF Example


2NF Example in DBMS

We have divided our 1NF table into two tables viz. Table 1 and Table2. Table 1 contains member information. Table 2 contains information on movies rented.

We have introduced a new column called Membership_id which is the primary key for table 1. Records can be uniquely identified in Table 1 using membership id.


3NF (Third Normal Form) Rules :

  • Rule 1- Be in 2NF
  • Rule 2- Has no transitive functional dependencies

To move our 2NF table into 3NF, we again need to again divide our table.

3NF Example :

Below is a 3NF example in an SQL database:


3NF Example


3NF Example


Example of 3NF in Database


We have again divided our tables and created a new table which stores Salutations.

There are no transitive functional dependencies, and hence our table is in 3NF

In Table 3 Salutation ID is primary key, and in Table 1 Salutation ID is foreign to primary key in Table 3


What are transitive functional dependencies?

A transitive functional dependency is when changing a non-key column, might cause any of the other non-key columns to change

Consider the table 1. Changing the non-key column Full Name may change Salutation.


Transitive functional dependencies in Database


BCNF (Boyce-Codd Normal Form)

Even when a database is in 3rd Normal Form, still there would be anomalies resulted if it has more than one Candidate Key.

Sometimes is BCNF is also referred as 3.5 Normal Form.

4NF (Fourth Normal Form) Rules

If no database table instance contains two or more, independent and multivalued data describing the relevant entity, then it is in 4th Normal Form.

5NF (Fifth Normal Form) Rules

A table is in 5th Normal Form only if it is in 4NF and it cannot be decomposed into any number of smaller tables without loss of data.

6NF (Sixth Normal Form) Proposed

6th Normal Form is not standardized, yet however, it is being discussed by database experts for some time. Hopefully, we would have a clear & standardized definition for 6th Normal Form in the near future…

That’s all to SQL Normalization!!!

Summary

  • Database designing is critical to the successful implementation of a database management system that meets the data requirements of an enterprise system.
  • Normalization in DBMS is a process which helps produce database systems that are cost-effective and have better security models.
  • Functional dependencies are a very important component of the normalize data process
  • Most database systems are normalized database up to the third normal forms in DBMS.
  • A primary key uniquely identifies are record in a Table and cannot be null
  • A foreign key helps connect table and references a primary key

No comments:

Post a Comment

Image File store outside of Oracle Database and show image into Apex Application

Directory Create : grant execute on utl_file to HRMS; CREATE OR REPLACE DIRECTORY STOCK_DIRECTORY AS 'C:\Program Files (x86)\Apache Sof...