lt15-nm
TRANSCRIPT
-
7/29/2019 lt15-NM
1/18
Database Systems and
Applications
Lecture 15
Normalization
-
7/29/2019 lt15-NM
2/18
Normalization & Normal form
NormalizationIt is a tool to validate and improve t logicaldesign, so that it satisfies certainconditions that avoid unnecessary
duplication of data.It is based on the analysis of functionaldependencies.
Normal form
It is a state of relation that results byapplying simple rules regarding functionaldependencies (or relationships betweenattributes) to that relation.
-
7/29/2019 lt15-NM
3/18
Normalization is often executed as aseries of steps. Each stepcorresponds to a specific normal formthat has known properties.
As normalization proceeds, therelations become progressively morerestricted in format, and also less
vulnerable to update anomalies. For the relational data model, it isimportant to recognize that it is onlyfirst normal form (1NF) that is critical
in creating relations. All the
-
7/29/2019 lt15-NM
4/18
Update Anomalies
Relations that have redundant datamay have problems called update
anomalies, which are classified as ,
Insertion anomaliesDeletion anomalies
Modification anomalies
-
7/29/2019 lt15-NM
5/18
-
7/29/2019 lt15-NM
6/18
Steps in normalizationTable with multi-valued attributes
1st normal form
2nd normal form
3rd normal form
Boyce-Coddnormal form
4th normal form
5th normal form
Remove multi-valued attributes
Remove partialdependencies
Removeremaining anomalies
resulting from functionaldependencies
Remove transitive
dependencies
Remove multi-valued dependencies
Remove remaining
anomalies
-
7/29/2019 lt15-NM
7/18
Definition of 1NF
First Normal Form is a relation in which the intersection of each
row and column contains one and only one value.
There are two approaches to removing repeating groups from
unnormalized tables:
1. Removes the repeating groups by entering appropriate
data in the empty columns of rows containing the repeating
data.
2. Removes the repeating group by placing the repeatingdata, along with a copy of the original key attribute(s), in a
separate relation. A primary key is identified for the new
relation.
-
7/29/2019 lt15-NM
8/18
First Normal Form (1NF)
A relation is in 1NF if it contains nomulti valued attributes. Ex: st_id name h_no r_no c_no year
sem grade
2009P7PS001 Venu BH1 005 CSGC 210 2010-11
2 ACSGC222 2010-11
2 B
2009P7PS020 Amit BH2 068 CSGC210 2010-112 B
CSGC230 2010-112 A
EEGC245 2010-
11 2 A
-
7/29/2019 lt15-NM
9/18
1NF (cont.)
Ex:
st_id name h_no r_no c_no year
sem grade2009P7PS001 Venu BH1 005 CSGC210 2010-11
2 A
2009P7PS001 Venu BH1 005 CSGC222 2010-11
2 B2009P7PS020 Amit BH2 068 CSGC210 2010-11
2 B
2009P7PS020 Amit BH2 068 CSGC230 2010-112 A
2009P7PS020 Amit BH2 068 EEGC245 2010-11
-
7/29/2019 lt15-NM
10/18
Full functional dependency
Full functional dependency indicates that if A and B
are attributes of a relation, B is fully functionally
dependent on A if B is functionally dependent on A,
but not on any proper subset of A.
A functional dependency AB is partially dependentif
there are some attributes that can be removed from A and
the dependency still holds.
-
7/29/2019 lt15-NM
11/18
Second Normal Form (2NF)
A relation is in 2NF if it is in 1NFand every non key attribute isfully functionally dependent on
the primary key.
i.e., no non key attribute isfunctionally dependent on part(but not all) of the primary key.
-
7/29/2019 lt15-NM
12/18
2NF (cont.)
A relation that is in 1NF will be in 2NFif any one of the following conditionsapplies:
The primary key consists of onlyone attribute (st_id in STUDENT1).
No non key attributes exist in therelation (i.e., all the attributes arepart of the primary key in therelation)
Every non key attribute is
functionally dependent on the full
-
7/29/2019 lt15-NM
13/18
Examples
st_id st_name h_no r_no address
STUDENT1
STUDENT2
st_id c_no st_name h_no r_no address sem year grade
-
7/29/2019 lt15-NM
14/18
2NF (cont.)
The relation STUDENT2 is not in2NF.
The primary key in this relation iscomposite key st_id, c_no.
In this the nonkey attributesname, h_no, r_no, address arefunctionally dependent on part of
the primary key (st_id) but not onc no.
-
7/29/2019 lt15-NM
15/18
2NF (contd.)
A partial functional dependencyis a functional dependency inwhich one or more non key
attributes are functionallydependent on part of the primarykey.
For example, in STUDENT2, thepartial dependency creates
redundancy. It leads to
-
7/29/2019 lt15-NM
16/18
2NF (cont.)
In this example
the redundancy is the attributesname, h_no and r_no will appear inall the rows of the student hastaken courses
when there is change in h_no and/orr_no, we have to update it in morethan one row depending upon thenumber of courses a student hastaken. The anomaly may occur even
-
7/29/2019 lt15-NM
17/18
2NF (cont.)
So to convert a relation to 2NF, it is necessaryto decompose the relation into new relationsthat satisfy one (or more) of the previouslydescribed conditions.
Ex : We shall decompose the relationSTUDENT2 into two relations.
STUDENT1(st_id, name, h_no, r_no, adddress) ST_COURSE(st_id, c_no, sem, year, grade)
-
7/29/2019 lt15-NM
18/18
If a relation cant be convertedto the second normal form, yourisk data redundancy and
difficulty in changing data. Toconvert first-normal-form tablesto second-normal-form tables,remove columns that are notdependent on the primary key.