What is meant by Normalization in RDBMS?
Normalization is a systematic approach of decomposing tables to eliminate data redundancy and undesirable characteristics like Insertion, Update and Deletion Anamolies.
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 – When you tried to delete a record, but parts of it was not deleted because of unawareness, the data is also saved somewhere else.
Insert anomalies – When you 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.
What are different types of Normal Forms?
1 NF (First Normal Form):
For First Normal form following rules must be followed:
2NF (Second Normal Form):
Second normal form states that it should meet all the rules for 1NF and there must be no partial dependences of any of the columns on the primary key.
A database is in second normal form if it satisfies the following conditions:
Consider a table with following attributes:
CREATE TABLE LIBRARY(
ST_ID INT NOT NULL,
ST_NAME VARCHAR (30) NOT NULL,
BOOK_ID INT NOT NULL,
BOOK_NAME VARCHAR (20) NOT NULL,
AUTHOR_NAME CHAR (30) NOT NULL,
ISSUE_DATE DATETIME NOT NULL,
RETURN_DATE DATETIME NOT NULL,
PRIMARY KEY (ST_ID, BOOK_ID)
);
This table is in first normal form, in that it obeys all the rules of first normal form. In this table, the primary key consists of ST_ID and BOOK__ID.
However, the table is not in second normal form because there are partial dependencies of primary keys and columns. ST_NAME is dependent on ST_ID, and there's no real link between a Student's name and what book he issued. Book name and author are also dependent on BOOK_ID, but they are not dependent on ST_ID, because there's no link between a ST_ID and an AUTHOR_NAME or their ISSUE_DATE.
To make this table comply with second normal form, you need to separate the columns into three tables.
First, create a table to store the STUDENT details as follows:
CREATE TABLE STUDENT(
ST_ID INT NOT NULL,
ST_NAME VARCHAR (20) NOT NULL,
PRIMARY KEY (ST_ID)
);
Next, create a table to store details of each BOOK:
CREATE TABLE BOOKS(
BOOK_ID INT NOT NULL,
AUTHOR_NAME CHAR (20) NOT NULL,
PRIMARY KEY (BOOK_ID)
);
Finally, create a third table storing just ST_ID and BOOK_ID to keep track of all the books issue to a student:
CREATE TABLE LIBRARY_ISSUE(
ST_ID INT NOT NULL,
BOOK_ID INT NOT NULL,
ISSUE_DATE DATETIME NOT NULL,
RETURN_DATE DATETIME NOT NULL,
PRIMARY KEY (ST_ID, BOOK_ID)
);
NF (Third Normal Form)
First and foremost thing is that a table has to be in 2NF to be in 3NF. Next the rule is: remove to a new table any non-key attributes that are more dependent on other non-key attributes than the table key. Ignore tables with zero or only one non-key attribute (these go straight to 3NF with no conversion).
The process is as follows:
If a non-key attribute is more dependent on another non-key attribute than the table key:
Thus a table is in third normal form if:
545 videos|966 docs|373 tests
|
1. What is database normalization? |
2. What are the different types of database normalization? |
3. How does the first normal form (1NF) achieve database normalization? |
4. What is the purpose of the second normal form (2NF) in database normalization? |
5. How does Boyce-Codd Normal Form (BCNF) differ from other normal forms? |
545 videos|966 docs|373 tests
|
|
Explore Courses for UPSC exam
|