0% found this document useful (0 votes)
32 views9 pages

Module II Normal Form (NF1, NF2, NF3, BCNF)

Normal form

Uploaded by

N M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views9 pages

Module II Normal Form (NF1, NF2, NF3, BCNF)

Normal form

Uploaded by

N M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

DBMS – Module 2 Dr.I.

Jasmine

NORMAL FORMS
NORMALIZATION
Introduction
Database normalization is the process of organizing the attributes of database to reduce or
eliminate data redundancy (having same data but at different places) from a relation or set of relations.
It is also used to eliminate the undesirable characteristics like Insertion, Update and Deletion Anomalies.
Normalization divides the larger table into the smaller table and links them using relationship. The
normal form is used to reduce redundancy from the database table.
Problems because of data redundancy
Data redundancy unnecessarily increases size of database as same data is repeated on many
places. Inconsistency problems also arise during insert, delete and update operations.
Functional Dependency
Functional Dependency is a constraint between two sets of attributes in a relation from a
database. Functional dependency is denoted by arrow (→). If an attributed A functionally determines B,
then it is written as A → B.
For example employee_id → name means employee_id functionally determines name of
employee. As another example in a time table database, {student_id, time} → {lecture_room}, student
ID and time determine the lecture room where student should be.
A function dependency A → B mean for all instances of a particular value of A, there is same
value of B.
For example in the below table A → B is true, but B → A is not true as there are different values
of A for B = 3.
A B
1 3
2 3
4 0
1 3
4 0

Types of Functional dependency

1 Dr.I.Jasmine
DBMS – Module 2 Dr.I.Jasmine

Trivial Functional Dependency


X –> Y is trivial only when Y is subset of X.
Examples
ABC --> AB
ABC --> A
ABC --> ABC
Non Trivial Functional Dependencies
X –> Y is a non trivial functional dependencies when Y is not a subset of X.
X –> Y is called completely non-trivial when X intersect Y is NULL.
Examples:
Id --> Name,
Name --> DOB
Anomalies in DBMS
There are three types of anomalies that occur when the database is not normalized. These are –
Insertion, update and deletion anomaly.
Example: Suppose a manufacturing company stores the employee details in a table named employee
that has four attributes: emp_id for storing employee’s id, emp_name for storing employee’s name,
emp_address for storing employee’s address and emp_dept for storing the department details in which
the employee works. At some point of time the table looks like this:

emp_id emp_name emp_address emp_dept

101 Rick Delhi D001

2 Dr.I.Jasmine
DBMS – Module 2 Dr.I.Jasmine

101 Rick Delhi D002

123 Maggie Agra D890

166 Glenn Chennai D900

166 Glenn Chennai D004

The above table is not normalized.


Update anomaly: In the above table there are two rows for employee Rick as he belongs to two
departments of the company. If the address of Rick needs to be updated then it has to be updated 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, Rick 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 the details of the particular employee cannot be inserted into the table
if emp_dept field doesn’t allow nulls.
Delete anomaly: Suppose, if at a point of time the company closes the department D890 then deleting
the rows that are having emp_dept as D890 would also delete the information of employee Maggie since
she is assigned only to this department.
To overcome these anomalies the data must be normalized.
Types of Normal Forms

3 Dr.I.Jasmine
DBMS – Module 2 Dr.I.Jasmine

Normal Description
Form
1NF A relation is in 1NF if it contains an atomic value.
2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are fully functional
dependent on the primary key.
3NF A relation will be in 3NF if it is in 2NF and no transition dependency exists.
4NF A relation will be in 4NF if it is in Boyce Codd normal form and has no multi-valued
dependency.
5NF A relation is in 5NF if it is in 4NF and not contains any join dependency and joining
should be lossless.

First Normal Form


First Normal Form is defined in the definition of relations (tables) itself. This rule defines that
all the attributes in a relation must have atomic domains. The values in an atomic domain are indivisible
units.
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:
emp_id emp_name emp_address emp_mobile
101 Herschel New Delhi 8912312390
102 Jon Kanpur 8812121212
9900012222
103 Ron Chennai 7778881212
104 Lester Bangalore 9990000123
8123450987

Two employees (Jon & Lester) are having two mobile numbers so the company stored them in
the same field as seen 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.

4 Dr.I.Jasmine
DBMS – Module 2 Dr.I.Jasmine

To make the table complies with 1NF the table should have the data like this:
emp_id emp_name emp_address emp_mobile
101 Herschel New Delhi 8912312390
102 Jon Kanpur 8812121212
102 Jon Kanpur 9900012222
103 Ron Chennai 7778881212
104 Lester Bangalore 9990000123
104 Lester Bangalore 8123450987

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 candidate-key, is known as a prime
attribute.
• Non-prime attribute − an attribute, which is not a part of the prime-key, is said to be a non-
prime attribute.
If second normal form is followed, then every non-prime attribute should be fully functionally dependent
on prime key attribute. That is, if X → A holds, then there should not be any proper subset Y of X, for
which Y → A also holds true.
Example: Suppose a school wants to store the data of teachers and the subjects they teach. They create
a table that looks like this: Since a teacher can teach more than one subjects, the table can have multiple
rows for a same teacher.
teacher_id subject teacher_age
111 Maths 38
111 Physics 38
222 Biology 38
333 Physics 40
333 Chemistry 40

5 Dr.I.Jasmine
DBMS – Module 2 Dr.I.Jasmine

Candidate Keys: {teacher_id, subject


Non prime attribute: teacher_age
The table is in 1 NF because each attribute has atomic values. However, it is not in 2NF because
non prime attribute teacher_age is dependent on teacher_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:
teacher_details table:
teacher_id teacher_age
111 38
222 38
333 40
teacher_subject table:
teacher_id subject
111 Maths
111 Physics
222 Biology
333 Physics
333 Chemistry

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


Third Normal form (3NF)
A table design is said to be in 3NF if both the following conditions hold:
• Table must be in 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.

6 Dr.I.Jasmine
DBMS – Module 2 Dr.I.Jasmine

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_zip emp_state emp_city emp_district
1001 John 282005 UP Agra Dayal Bagh
1002 Ajeet 222008 TN Chennai M-City
1006 Lora 282007 TN Chennai Urrapakkam
1101 Lilly 292008 UK Pauri Bhagwan
1201 Steve 222999 MP Gwalior Ratan

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:
employee table:
emp_id emp_name emp_zip
1001 John 282005
1002 Ajeet 222008
1006 Lora 282007
1101 Lilly 292008
1201 Steve 222999
employee_zip table:
emp_zip emp_state emp_city emp_district
282005 UP Agra Dayal Bagh
222008 TN Chennai M-City
282007 TN Chennai Urrapakkam

7 Dr.I.Jasmine
DBMS – Module 2 Dr.I.Jasmine

292008 UK Pauri Bhagwan


222999 MP Gwalior Ratan

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 Austrian Production and planning D001 200
1001 Austrian stores D001 250
1002 American design and technical support D134 100
1002 American Purchasing department D134 600

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 Austrian
1002 American
emp_dept table:
emp_dept dept_type dept_no_of_emp
Production and planning D001 200
stores D001 250
design and technical support D134 100

8 Dr.I.Jasmine
DBMS – Module 2 Dr.I.Jasmine

Purchasing department D134 600


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.
Normalization Drawbacks
By limiting redundancy, normalization helps maintain consistency and saves space. But
performance of querying can suffer because related information that was stored in a single relation is
now distributed among several.

9 Dr.I.Jasmine

You might also like