0% found this document useful (0 votes)
63 views

Different Normal Forms

The document discusses different normal forms including 1NF, 2NF, and 3NF. The key points are: 1. 1NF requires that attributes be atomic and cannot contain repeating groups. To satisfy 1NF, relations must be free of multi-valued attributes. 2. 2NF builds on 1NF and requires that non-key attributes are fully dependent on the primary key. In 2NF, relations cannot have non-key attributes that are dependent on only part of a composite primary key. 3. The goal of normalization is to eliminate redundancy and anomalies by decomposing relations into multiple relations in higher normal forms. This is done by identifying functional dependencies and moving attributes to avoid partial dependencies.

Uploaded by

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

Different Normal Forms

The document discusses different normal forms including 1NF, 2NF, and 3NF. The key points are: 1. 1NF requires that attributes be atomic and cannot contain repeating groups. To satisfy 1NF, relations must be free of multi-valued attributes. 2. 2NF builds on 1NF and requires that non-key attributes are fully dependent on the primary key. In 2NF, relations cannot have non-key attributes that are dependent on only part of a composite primary key. 3. The goal of normalization is to eliminate redundancy and anomalies by decomposing relations into multiple relations in higher normal forms. This is done by identifying functional dependencies and moving attributes to avoid partial dependencies.

Uploaded by

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

Different Normal Forms

(1 NF, 2 NF and 3 NF)


Normalization

 Normalization theory provides a mechanism for analyzing and


refining the schema produced by an E-R design so that certain
problems can be avoided
It is a technique which tries to say how to design good database in
formal manner
Goal of Normalization

 Decide whether a particular relation R is in good form

In case, R is not in good form, decompose R into set of relations


(r1,r2,…rn) such that
(i) each relation is in good form
(ii) decomposition is lossless

 Normalization tries to design a good data base by eliminating


redundancy and different anomalies (insert, delete, update)
First Normal Form (1 NF)
 A relation R is said to be in first normal form if the domains of the attributes
of R are atomic
 Value is atomic if the value can not be decomposed into smaller parts
 Domain of an attribute is atomic if it is indivisible
 Examples of atomic values: integer, char, first name, last name, age, phone
number, roll number
 Examples of non atomic values : ISBN, address, set of numbers , set of phone
numbers, name, set of names
 Name is non atomic as it can be decomposed into first name, middle name
and sur name. Similarly, address is composite attribute and can be
decomposed into smaller pieces
Is Relation in 1 NF ?
Student

Roll No Name Age Phone_number


101 Robin 19 0332456123, 9832045673
102 Julia 18 9434782241
103 Mary 19 9834567234, 9835567182
104 Ricky 20 03432567123

The relation Student is not in first normal form (1 NF) as the attribute phone number is
multivalued and non atomic

To make the relation Student compiles with 1NF , we have the organize the data such way that
the relation has no non atomic values.
Following Relation in 1 NF

Student

• Relation Student is in first normal form


• Roll number is the primary key used for identifying the records uniquely
Another Way to Organize the Data of Student Relation
Student
Roll no Name Age Phone_number

101 Robin 19 0332456123


101 Robin 19 9832045673
102 Julia 18 9434782241
103 Mary 19 9834567234
103 Mary 19 9835567182
104 Ricky 20 03432567123

• Now, the relation Student is in first normal form


• Here, roll number is not the primary key as roll no phone number does not hold
• (Roll no, phone_number ) is the key for identifying the records uniquely
• First normal form has certain level of redundancy
Good Design
Student_ph
Student
Roll No Phone Number
Roll no Name Age 101 0332456123
101 Robin 19 101 9832045673
102 Julia 18 102 9434782241
103 Mary 19 103 9834567234
104 Ricky 20 103 9835567182
104 03432567123

 Both Student and Student_ph are in 1 NF


 Roll no in Student relation is primary key where Roll no in Student_ph is foreign key
 No redundancy in Student table
Second Normal Form ( 2NF)
 A relation R is in second formal form if and only if
 R is in 1NF
 If R has no partial functional dependency i.e. no non-prime attribute of R is
functionally dependent on any proper subset of a candidate key

 An attribute is said to be a prime attribute if it is the part of a candidate key


 An attribute is a non-prime if it is not part of a candidate key
 Example: Let, Student_Enrol (stu_id, stu_name, course_id, course_name,
credit, grade) be a relation with functional dependencies

(stu_id, course_id) (stu_name, course_name, credit, grade)


Here, stu_id , course_id are prime attributes while stu_name, course_name,
grade, credit are non-prime attributes
Full Functional Dependency
Full functional dependency
• An attribute in relation R is fully dependent on another attribute if it is functionally dependent
on that attribute and is not dependent on any of its proper subset
• Functional dependency X Y is a full functional dependency if removal of any attribute , say A,
from X means that the dependency does not hold any more

Example:
Relation R1 = (EmpID, ProjID, Days)
Here, an employee can work more than one projects and more than one employees can work on a
project
Therefore, candidate key is (EmpID, ProjID)

Full functional dependency : (EmpID, ProjID) Hours


Here, if we remove ProjID or EmpID from L.H.S, dependency does not hold any more. Removal of
any attribute in L.H.S does not determine R.H.S
Partial Functional Dependency

Partial functional dependency


When a non-prime attribute in relation R is functionally dependent on any proper
subset of a candidate key, we say the non prime attribute has partial dependency on
the candidate key
For example, in FD: PQ Z, if either P alone or Q alone can uniquely determine Z,
then this is said to be partial functional dependency. We read it as Z is partially
dependent of either P or Q
Example
Example:
Emp_Project =(Eid, Ename, Pid, Pname, Days)
Candidate key= (Eid, Pid)
Prime attributes: Eid , Pid Non-prime attributes = Ename, Pname,Days
This relation has a set of functional dependencies FDs:
(Eid, Pid) Ename
(Eid, Pid) Pname
(Eid, Pid) Days // full functional dependency
Eid Ename
Pid Pname
Here, Eid is the proper subset of the candidate key and Ename is non prime attribute. Ename
is functionally dependent on Eid. We say Ename is partially functionally dependent on the
candidate key
If we remove any attribute from (Pid, Eid), Ename is still be determined
Is the relation in 2NF
Emp_Project
EID Ename PID Pname Days
101 Ricky P1 A 120
101 Ricky P2 B 60
102 Reema P1 A 60
103 Sid P3 C 120
102 Reema P3 C 30

Relation Emp_Project is 1 NF but not in 2 NF as it has partial functional dependency


Candidate Key: (EID, PID)
FDs:
(EID, PID) (Ename, Pname, Days)
EID Ename
PID Pname
Relation/table can be converted into 2 NF by removing the partial functional dependencies. To remove partial
functional dependency, we can decompose the relation , move the attributes which are causing partial
dependency and move them to a new relation
Following Relations Are In 2 NF
Emp Project

EID Ename PID Pname


101 Ricky P1 A
102 Seema P2 B
103 Sid P3 C

Emp_Proj

EID PID Days


101 P1 120
101 P2 60
102 P1 60
102 P3 30
103 P3 120
How to Convert 1NF relation to 2NF relation(s)

2NF applies only to relations with composite primary keys, that is, relations
with a primary key composed of two or more attributes
A 1NF relation with a single primary key is automatically in at least 2NF
2NF is a relation that is already in 1NF and in which non prime attribute is
functionally dependent on the proper subset of the candidate key of the
relation
A relation in 1NF can be converted into 2NF by removing the attributes that
are partially dependent on the prime attribute. These attributes are placed in
a new relation along with the prime attribute on which it is dependent
Another Example of 2NF
Student_Enrol
StuID CourseID CourseName Marks Credit
101 CSC01 C 80 3
101 BT01 Bioscience 60 2
102 CSC01 C 66 3
102 BT01 Bioscience 76 2

 Table Student-Exam is in 1 NF but not in 2NF as it has partial dependency


 StuID Primary key
 CourseID Primary key
 Candidate key = (StuID, CourseID). It is also composite key
 FDs:
(StuID,CourseID) Coursename, Marks, Credit
CourseID CourseName
CourseID Credit
The Following Tables are in 2 NF

Course Student_Enrol

CourseID CourseName Credit StuID Course ID Marks


CSC01 C 3 101 CSC01 80
BT01 Bioscience 2 101 BT01 70
102 CSC01 66
102 BT01 76

#Course
PK: CourseID
CourseID CorseName, Credit

# Student_Marks
CK: (StuID, CourseID)
StuID,CourseID Marks
Transitive Functional Dependency
 The functional dependency X Z is transitive functional dependency in R when for a
set of attributes Y in R if X Y and Y Z hold where Y is not subset of any key of R
Example : Student (Sid, Sname, Address, Deptno, Hod)
PK: Sid
Sid Sname
Sid Address
Sid Deptno
Deptno Hod
Sid Hod is transitive dependency

So, Hod for a particular department appears multiple time, causing redundency
Relation which is in 2 NF has still redundancy and transitive dependency
Third Normal Form
A relation R is in 3NF if and only if
 The relation R is already in 2 NF
 No non prime attribute of R is transitively dependent on any key of R

 Student relation is not in 3 NF, we decompose Student into smaller relations


Student (Sid, Sname, Address, Deptno) in 3NF
Dept( Deptno, Hod) in 3 NF
 Redundancy is removed
Another definition of 3NF as follows:
A relation R is in 3 NF if and only if for every non trivial functional dependency X A, at
least one of the following conditions hold
 X is super key of R
 A is prime attribute
Another Example of 3 NF
Employee
EMPID EName Zip State City
101 John 123 WB Kolkata
102 Jovi 456 Delhi Anand Bihar
103 Dip 789 Mumbai Pune
104 Rina 019 Jammu Golap

Super key: {Emp ID}, {EmpID , EName}, {EmpID, EName, Zip},……


Candidate Key: {EmpID}
FD:
EmpID EName, Zip, State, City
Zip State
Zip City
Non prime attributes State and City are transitively dependent on primary key EmpID . This violates the
rule for 3 NF
Therefore, table Employee is not in 3 NF.
We have to convert table to 3 NF by moving Zip, state and city to new table (EmpZip) with zip is primary
key.
Relations are in 3 NF

Employee City_Info

EmpId EName Zip Zip State City


101 John 123 123 WB Kolkata
102 Jovi 456 456 Delhi Anand Bihar
103 Dip 789 789 Mumbai Pune
104 Rina 019 019 Jammu Golap
Examples

• Let R is relation (A, B, C, D, E)


A BC, BC AD, D E

Keys = A, BC
No prime attributes : D, E
So A D
D E
Hence, A E is transitive dependency. So R is not in 3 NF. It is in 2 NF
Examples

• Let relation student1( name, id, courseno, grade)


name, courseno grade
id, courseno grade
Name id
Id name
Find the normal form of student 1
Ans: candidate key= (name, courseno) , ( id, courseno)
No partial functional dependency. No transitive dependency. So relation is
in 3 NF
Examples

• Let relation R( A, B, C, D, E)
FDs: B A, A C, BC D, AC BE
Find the normal form.

Candidate keys: A, B
BC and AC are super keys
B A does not violate 2 NF rule, similarly other three FDs.
So , R is in 2 NF
L.H.S of all FDs are super keys. So R in 3 NF
Another Example of 3 NF
Let R (A,B,C,D) be a relation with following FDS. Check whether R is in 3NF or
not?
(i) AB C
(ii) AB D
(iii) C A
(iv) D B
Solution: Here, AB is one of the candidate key as AB can determine AB itself and
also C and D. So, AB determines all attributes of R.
But, C determines C and A. D determines D and B. From (i) and (ii) , we say AB is CK
Other CKs are AD, BC, CD
R is in 2 NF as C and D are not dependent on either A or B.
From (iii) C A , A is contained in a candidate key AB. Similarly, from (iv) D B. So, R is
in 3 NF
Advantages of 3 NF

 3 NF allows some redundancy


 However, it is weaker than BCNF, FDs can be checked in individual relations
without computing a join
 There is always a lossless join, dependency preservation decomposition in 3
NF

You might also like