Lecture #10
Lecture #10
الرحمن
الرحیم
2
OUTCOMES
• Normalizations(1nf (first normal form)
4
NORMALIZATION
• Normalization is a database design technique that reduces data
redundancy and eliminates undesirable characteristics like
Insertion, Update and Deletion Anomalies. Normalization rules
divides larger tables into smaller tables
5
PURPOSES OF NORMALIZATION
• It makes the database design efficient in performance
6 CHARACTERISTICS OF NORMALIZATION
7
FUNCTIONAL DEPENDENCY
• Functional dependency is a relationship between attributes. It mean
that if the value of one attributes is known, it is possible to obtain the
value of another attribute. Suppose there is a relation STUDENT with
following fields.
• STUDNENT (RegistrationNo, StudentName, Class)
• If value of RegistrationNo is known, it is possible to obtain the value
of StudentName. It means that StudentName is functionally depended
on RegistarationNo. An attribute B is functionally dependent on
attribute A if the value of A determines the value of B.
• Functionally dependency is written as follows:
RegistrationNo StudentName
8
FIRST NORMAL FORM (1NF)
• A relation in first normal form(1NF) if it does not contain a repeating
group. A repeating group is a set of one or more data items that may
occur a variable number of times in a tuple. The value in each attribute
value should be atomic and every tuple should be unique. Each cell in
a relation should contain only one value. An example of un-normalized
relation is as follows:
9
FIRST NORMAL FORM (1NF)
Accountant Skill No Skill Proficien Accountant Accountant Group No Group Group
No Category cy No Name age City supervisor
The above relation is un-normalized because it contains repeating group of three attributes skill
number, skill category and proficiency number. All three fields contains more than one value.
In order to convert this relation in first normal form, these repeating groups should be removed.
The following relation is in first normal form:
10
FIRST NORMAL FORM (1NF)
Primary key
11
PROBLEMS IN 1NF
• Updating problems: Suppose the user wants to change the name of accountant
number 35 to “M. Daud”. He has to the name in all records in which accountant
number 35 appears. This process updating can be very lengthy.
• Addition problem: suppose the user wants to add another skill number in the
table. It is not possible until an accountant with that skill exists because both
skill number and accountant number are used as primary key in the above table.
• Deletion problem: suppose the user wants to delete the record of supervisor
Ghafoor. If he deletes the whole record in which Ghafoor appears, the
information about accountant will also be lost.
• Inconsistent data: the above table contain inconsistent data. There are three
records of accountant number 35. it is possible that there are two different names
with accountant number 35 in two different records. The user can make this
error during updating.
12
FULLY FUNCTIONAL DEPENDENCY
• In a relation R, attributes B of R is fully functionally depended on an attribute
or set of attributes A of R if B is functionally dependent on A but not
functionally dependent on any other proper subset of A.
• Suppose there is a relation MARKS as follow:
• MARKS(ResgistrationNo, Subject, Marks)
• Assume that one student is studying many subjects. Both ResgitrationNo and
Subject are required to determine a particular marks. It can be written as
follows:
• ResgistrationNo, Subject Marks
• Here, Marks is fully dependent on both fields because it is not functionally
dependent on either RegistrationNo or Subject alone.
13
SECOND NORMAL FORM (2NF)
• A relation is in second normal form (2 NF) if it is in 1NF and if all
of its non-key attributes are fully function dependent on the whole
key. It means that none of non-key attributes are related to a part of
key.
• The above relation in 1NF has some attributes which are not
depending on the whole primary key. For example, accountant
name, account age and group information is determined by
accountant number and is not dependent on skill. The following
relation can be created in which all attributes are fully dependent
on primary key account number.
113 Systems
113 Systems
179 Tax
204 Audit
179 Tax
21 113 3
35 113 5
35 179 1
35 204 6
50 179 2
75 148 6
75 179 6
There are three relation in second normal form (2NF). The attributes of
all relation are fully dependent on the primary keys.
• The following analysis indicates whether the problems are eleiminated in 2NF or not.
• Updating problems: if the user needs to change the name of accountant number 35 to
“M. Daud” in 1NF, He must change the name in every records in which accountant
number 35 appears. But in 2NF, the record of none accountant appears only once. The
updating problem is eliminated in 2NF.
• Deletion problem: in 2NF, if the record of Ghafoor is deleted, it does not delete any
other record.
• Addition problem: in 1NF, it was not possible to enter a new skill number until an
accountant with that skill existed. In 2NF, any number of skills can be added in skill
relation without an accountant with that skill . It eliminates the addition problem.
• Inconsistent data: the record of one accountant appears only once in the database,
the possibility of inconsistent data is automatically eliminated.
18
TRANSITIVE DEPENDENCY
• Transitive dependency is a condition in which an attribute is dependent on an attribute that is not
part of the primary key.
• Suppose A,B, and C are attributes of a relation. If AB and BC then C is transitive
dependency on A via B provided that A is not functionally dependent on B or C.
• We can wirte :
• A transitive dependency occurs when one non-key attribute determines another non-key
attribute. In above relation, BookID determines CategoryID and CategoryID determines
CategoryDescription. CategoryDescription is transitively dependent on BookID attribute.
19
THIRD NORMAL FORM (3NF)
• A relation is in third normal form if it is in 2NF and if no non-key attribute
is dependent on another non-key attribute. It means that all non-key
attributes are functionally dependent only on primary key. There should be
no transitive dependency in a relation. In order to convert a relation to
3NF:
• Remove all attributes from the 2NF record that depend on another
non-key field.
• Place them into a new relation with the other attribute as the primary
key.
The accountant table in 2NF contains some attributes which are
depending on non-key attributes. Form example, Group City and Group
Supervisor are depending on a non-key field Group Number. A new
relation can be created as follow:
20
THIRD NORMAL FORM (3NF)
Primary key
21 Ali 55 52
35 Daud 33 44
50 Chohan 40 44
75 Zahid 52 52
The second table created form the accountant table in 1Nf is as follows:
21
THIRD NORMAL FORM (3NF)
Primary key
52 ISD Babar
44 LHR Ghapfoor
Both accountant table and Group table contain the attribute Group Number.
This attribute is used to join both tables.
The skill table in 2NF contains no attribute, which is depending on a non-key
attribute. It is already in third normal form and will be used without any
further change.
22
THIRD NORMAL FORM (3NF)
Primary key
113 Systems
179 Tax
204 Audit
23
THIRD NORMAL FORM (3NF)
Primary key
21 113 3
35 113 5
35 179 1
35 204 6
50 179 2
77 148 6
77 179 6
24
BOYCE CODD NORMAL FORM (BCNF)
Primary key
25
BOYCE CODD NORMAL FORM (BCNF)
• Assume that Part Name is unique. It means that no two parts can have the
same name. There are now two candidate key (Project ID, Part ID) and
(Project ID, Part Name).
• There are following dependencies:
• (Project ID, PartID) QtyUsed
• PartID PartName
• PartName PartID
• This relation satisfies 2NF because there are non non-key attributes that are
dependent on a subset of the primary key. Part Name is not a non-key
attribute, it sis part of a candidate key . There this relation is in 2Nf.
26
BOYCE CODD NORMAL FORM (BCNF)
• There are non transitive dependencies so the relation is in 3NF. PartID and
PartName are ignored by 3NF rule because they are both key attributes.
194 P02 1
27
FOURTH NORMAL FORM
• A relation is in 4NF if it is in BCNF and has no multi-valued decencies.
• Multi valued decencies.
• A multi-valued dependencies exists in a relation has at least three attributes, two
of them are multi-valued and their values depend on only the third attribute.
• Suppose there is a relation R(A, B, C). A multi-valued dependency exist if:
• A determines multiple value of B Student ID Subject Interest
28
FOURTH NORMAL FORM
• In the above example, a student can study many subject and can have many
interest. There are four records for Student ID 100. This is because we
have to used all possible combination of subjects and interest to make it
clear that a student with many subject can have any interest. Otherwise, it
would appear that reading can only occur with math and tennis can occur
only with Accounting.
Student ID Subject Interest
• Multi-valued dependencies are written as follow:
100 Math Reading
• StudentID Subject
100 Accounting Reading
• Sutdent ID Interest 100 Math Tennis
29
ANOMALIES IN MULTI-VALUED DECENCIES
• Suppose StudentID 100 decide to take another course “Economics”. it
requires the addition of two tuples i.e. one with combination of Reading
and one with combination of Tennis as follows:
30
CONTI…
Similarly, if a student wants to drop a subject, all tuples containing that
particular subject hast to be deleted.
• A relation is in 5NF if it is in 4NF and not contains any join dependency and joining
should be lossless.
• 5NF is satisfied when all the tables are broken into as many tables as possible in
order to avoid redundancy.
32
FIFTH NORMAL FORM (5NF)
SUBJECT LECTURER SEMESTER
• Suppose we add a new Semester as Semester 3 but do not know about the subject and
who will be taking that subject so we leave Lecturer and Subject as NULL. But all
three columns together acts as a primary key, so we can't leave other two columns
blank.
• So to make the above table into 5NF, we can decompose it into three relations P1, P2
& P3:
P1 P2 P3
SEMESTER SUBJECT SUBJECT LECTURER SEMSTER LECTURER
36
THE END