Unit3 Normalization
Unit3 Normalization
Suppose a manufacturing company stores the employee details in a table named employee that
has four attributes: empid for storing employee’s id, empname for storing employee’s name,
empstreet for storing employee’s address and empdept for storing the department details in which the
employee works. At some point of time the table looks like this:
Table_Product
Update anomaly: In the above table we have two rows for employee B as he belongs to two
departments of the company. If we want to update the address of B 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. B 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 empdept field
doesn’t allow nulls.
Delete anomaly: Suppose, if at a point of time the company closes the department D05 then deleting
the rows that are having empdept as D05 would also delete the information of employee C since he is
assigned only to this department.
In the below table contains non-atomic values , the values in the COLOR column in the first row can
be divided into "red" and "blue“. Hence it is not in 1NF.This table is in UNF (Un-Normalized Form).
Table_Product
100 red,blue 30
200 green 18
300 white 25
400 green,orange 40
500 red 21
2)There are no repeating columns. (Repeating columns means that a table contains two or more
columns that are closely related)., Each record needs to be unique. i.e., there are no duplicated rows in
the table For example Table_Product
100 red,blue 30
200 green 18
300 white 25
400 green,orange 40
500 red 21
To bring this table to first normal form, we split the table into two tables and now we have the
resulting tables:
Table_Product_Price Table_Product_Color
400 Orange
500 red
2)All non-key attributes are fully functional dependent on the primary key, ie., it has no partial
dependencies on the primary key.
TABLE_Purchase_details
1 1 Delhi
1 3 Chennai
2 1 Delhi
3 2 Kolkata
4 3 Chennai
This table has a composite primary key [Cust_ID, Store _ID]. The non-key attribute [Purchase
Location] only depends on [Store ID], which is only part of the primary key, ie., it has partial
dependency. As per the Second Normal Form there must not be any partial dependency of any
column on primary key.
To bring this table to second normal form, we break the table into two tables, and now we have the
following:
Table_purchase
Table_store
Cust_ID Store_ID
Store_ID Purchase_location
1 1
1 3 1 Delhi
2 1 2 Kolkata
3 2 3 Chennai
4 3
In the table [TABLE_STORE],the column [Purchase_Location] is fully dependent on the primary key of that
table,which is [Store_ID].
Such derived dependencies hold well in most of the situations. For example if we have
Roll Marks
And
Marks Grade
Then we may safely derive
Roll Grade.
This third dependency was not originally specified but we have derived it.
The derived dependency is called a transitive dependency when such dependency becomes
improbable. For example we have been given
Roll City
And
City STDCode
If we try to derive Roll STDCode it becomes a transitive dependency, because obviously
the
STDCode of a city cannot depend on the roll number issued by a school or college. In such a
case the
relation should be broken into two, each containing one of these two dependencies:
Roll City
And
City STD code)
For example, in the following table , street , city and state are unbreakably bound to their zip code.
The dependency between the zip code and the address is called as a transitive dependency . To bring
this table to third normal form, we break the table into two tables, and now we have the following
The advantages of removing transitive dependencies are mainly two-fold. First, the amount of data
duplication is reduced and therefore your database becomes smaller.The second advantage is data
integrity.
A relationship is said to be in BCNF if it is already in 3NF and the left hand side of every
dependency is a candidate key. A relation which is in 3NF is almost always in BCNF. Boyce and Codd
Normal Form is a higher version of the Third Normal form.
These could be same situation when a 3NF relation may not be in BCNF the following
conditions are found true.
The given relation is in 3NF. Observe, however, that the names of Dept. and Head of Dept. are
duplicated. Further, if Professor P2 resigns, rows 3 and 4 are deleted. We lose the information that
Rao is the Head of Department of Chemistry.
The normalization of the relation is done by creating a new relation for Dept. and Head of Dept. and
deleting Head of Dept. form the given relation. The normalized relations are shown in the following.
4NF: A database table is said to be in 4NF if it is in BCNF and contains no multivalued dependency.
A table is said to have multi-valued dependency, if the following conditions are true,
For a dependency A → B, if for a single value of A, more than one value of B exists, then the table may
have multi-valued dependency.
Also, a table should have at-least 3 columns.
And, for a table with A,B,C , if there is a multi-valued dependency between, A and B, then B and C should
be independent of each other.
Reg_id Subject Hobby
101 C Reading
101 JAVA Singing
102 C# Cricket
102 PHP football
In the table above, student with Reg_id 101 has opted for two subjects C and Java and , has two
hobbies,Reading and Singing
In the table above, there is no relationship between the columns Subject and hobby. They are
independent of each other . So there is multi-value dependency, which leads to un-necessary repetition
of data. To eliminate this dependency, divide the table into two as below
Reg_id Subject Reg_id Hobby
101 C 101 Reading
101 JAVA 101 Singing
102 C#
102 Cricket
102 PHP
102 football