Normmmalizzarion
Normmmalizzarion
Dependency &
Normalization
Dependen
• A dependency
cy in a whe
information
occurs stored in database n
the
uniquely determines other information
same storedtabl
in
the same table. database e
Functional
• A
Dependency
functional dependency is defined as a
constraint between two sets of attributes in a
relation from a database.
Records S3 P2 300
Key
•
s
key is a set of attributes that uniquely identifies
an entire tuple, a functional dependency
allows us to express constraints that uniquely
identify the values of certain attributes.
RollNo
System_Used
Functional
Cours_Code Hourly_Rate
Dependence
Course_Name
Diagram
A*
A* A*
B
Convert B D
* To
*
C
C
D
1N 2N
F F
Second Normal Form
HOURS_ASSIG (2NF)
STUDENT_SYSTEM_CH
NED
Cours ARGE
Roll Name System Hourly
Roll Total
e No Hours No Used Rate
Code
100 A1 P–I 20
C1 100 7 COUR
C1 101 3 101 A2 P – II 30 Cours SE
Course Teacher
C1 102 6 102 A3 Celeron 10 e Name Name
103 A4 P – IV 40 Code
C1 103 1
Visual
C2 100 7 100 A1 P–I 20 C1 ABC
Basic
C2 104 3 104 A5 P – III 35
Oracle
105 A6 P – II 30 C2 DEF
C2 105 1 & Dev
C2 101 2 101 A2 P – II 30
106 A7 P – IV 40 C3 C++ KJP
C3 106 3
107 A8 P – IV 40 C4 Java Kumar
C3 107 2
C3 108 1 108 A9 P–I 20
C4 109 2 109 A10 Cyrix 20
Removal of
Anomalies of
• Insert Anomalies: It is now possible to
1NF Relations
insert the information about the student
who does not join any course e.g. we can
store the information about the Rollno 110
who does not join any course in
STUDENT_SYSTEM_CHARGE
database. Similarly now we are able to
store the information about the course
which has no enrolled student e.g. we can
store that C1 course is of Visual Basic in
COURSE table.
Removal of
Anomalies of
1NF Relations
• Updat Anomalies: Now, it is
e
change the teacher possible
for a particular
to course
in the COURSE table through a single
modification. So, no data inconsistency will
arise.
•Delete Anomalies: in the revised
structure, we can delete the information of
student having Rollno 109 without losing
the information about his course i.e. C4.
Anomalies in
• Relations 2NF
in 2NF are still to
subject
anomalies. Let us assume that the data
system
on which a student works functionally
determines the hourly rate charged from
the student i.e.
System_Used Hourly_Rate
•Dueto this fact the anomalies
will occur in case of 2NF.
Anomalies in 2NF
• Insert Relations
Anomalies: Insertion anomalies
occur in the Student_System_Charge
relation. For example, consider a situation
where we would like to set in advance the
rate to be charged from the students for a
particular system. We can not insert this
info. Until there is a student assigned to
that type of system because Rollno is the
primary key for this relation and we can
not insert the null value into it.
Anomalies in
2NF
• Update Anomalies: Update will
also occur in the Student_System_Charge
anomalies
relation because there may be several
students which are working on the same
type of the system. If the Hourly_Rate for
a particular system changes, we need to
make sure that the corresponding rate is
changed for all the students that work on
that type of system. Otherwise, the
database may end up in an inconsistent
state.
Anomalies in
2NF
• Delete Anomalies: Delete anomalies will
also occur in the
Student_System_Charge relation. This
type of anomaly occurs whenever we
delete the tuple of a student who happens
to be the only student left which is
working on a particular system. In this
case, we will also lose the information
about the rate that we charge for that
particular system.
Prime and nonprime
attributes
• An attribute of a relation schema R is
called Prime attribute if it is a member of
some candidate key of R.
• An attribute is called non prime if it is not a
prime attribute i.e. it is not the member of
any candidate key.
Third Normal Form
• A relation
(3NF)
R is in 3NF if and if
following
only conditions are the
simultaneously:
satisfied
–R is already in 2NF
–No nonprime attribute functionally determines any
other non-prime attribute Or No nonprime attribute is
transitively dependent on the key
•The objective of transforming
relations into 3NF is to remove all transitive
dependencies.
Third Normal Form
(3NF) Functional
Name
Dependence
Diagram
RollNo System_Used RollNo System_Used
System_Used
Hourly_Rate
Hourly_Rate
It Means RollNo
Hourly_Rate
Rule to Resolve Transitivity
Dependence
A*
A* B
B Convert
To B C
C 2N 3N
F F
Third Normal Form
Roll System
(3NF)
STUDENT_SYSTEM_CHARGE
Name
STUDENT_SYSTEM
Hourly Roll Name System
No Used Rate No Used
100 A1 P–I 20 100 A1 P–I
CHARGES
System Hourly
101 A2 P – II 30 101 A2 P – II
Used Rate
102 A3 Celeron 10 102 A3 Celeron
Celeron 10
103 A4 P – IV 40 103 A4 P – IV
Cyrix 20
100 A1 P–I 20 Convert 100 A1 P–I
To P–I 20
104 A5 P – III 35 104 A5 P – III
P – II 30
105 A6 P – II 30 105 A6 P – II
P – III 35
101 A2 P – II 30 101 A2 P – II
P – IV 40
106 A7 P – IV 40 106 A7 P – IV
107 A8 P – IV 40 107 A8 P – IV
108 A9 P–I 20 108 A9 P–I
109 A10 Cyrix 20 2N 109 A10 Cyrix 3N
Removal of
Anomalies of
2NF In
• Insert Anomalies: Relations
the revised structure
of STUDENT_SYSTEM and CHARGES,
it is possible to insert in advance the rate
to be charged from the students for a
particular system.
• Update Anomalies: If the Hourly_Rate for
a particular system changes, we need
only to change a single record in
CHARGES database for that particular
system.
Removal of
Anomalies of
2NF Relations
• Delete Anomalies: We delete the tuple of
a student who happens to be the only
student left which is working on a
particular system without losing the
information about the rate that we charge
for that particular system.
Anomalies in
3NF
• The relations in 3NF are suceptible to data
anomalies particularly when the relations
have two overlapping candidate keys or
when a non-prime attribute functionally
determines a prime attribute. Let us
consider the example which illustrate
these anomalies:
Anomalies in
3NF
• We can take a case of Supplier_Part
Table having following attributes:
Supplier_Part(Sno, Sname, Pno, Qty)
Lets suppose that Sname is
unique for each Sno as shown
below: Sno Sname Pno Qty
S1 Rahat P1 300
S2 Raju P2 200
S1 Rahat P3 100
S2 Raju P1 200
Anomalies in
3NF
• This relation has two candidate keys:
(Sno, Pno) and (Sname, Pno) that overlap
on the attribute Pno. The relation is in
3NF because there is single nonprime
attribute.
• The relation is susceptible to update
anomalies e.g. if one of the supplier
changes its name, then we have to make
multiple changes which is equal to the
number part supplied by that particular
Steps of
Normalization
Step 1. Create Unnormalized Relation
1N
Step 2. Separate Repeating & Non-
F
repeating Attributes