0% found this document useful (0 votes)
13 views36 pages

Lecture #10

Uploaded by

iqbaloriakhil890
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)
13 views36 pages

Lecture #10

Uploaded by

iqbaloriakhil890
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/ 36

‫بسم هللا‬

‫الرحمن‬
‫الرحیم‬

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

2
OUTCOMES
• Normalizations(1nf (first normal form)

• 2NF (second normal form)

• 3NF (third normal form)

• BCNF (boyce-codd normal form)

• 4NF (fourth normal form)

• 5NF (fifth normal form)

• 6NF (sixth normal form)

SALAM University, Kabul


Adopted from Reference Book No 1

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

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

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

5
PURPOSES OF NORMALIZATION
• It makes the database design efficient in performance

• It reduce the amount of data if possible


• It makes the design according to the rules of relational database.
• It identifies relationship between entities.

• It makes a design that allows simple retrieval of data.

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

6 CHARACTERISTICS OF NORMALIZATION

• Each relation must have a key field.

• All fields must contain atomic data.

• There must be no repeating fields.

• Each table must contain information about a single entity.

• Each field in a relation must depend on key fields.

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

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

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

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:

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

9
FIRST NORMAL FORM (1NF)
Accountant Skill No Skill Proficien Accountant Accountant Group No Group Group
No Category cy No Name age City supervisor

21 113 Systems 3 Ali 55 52 ISD Babar

35 113 Systems 5 Daud 33 44 LHR Ghapfoor


179 Tax 1
204 Audit 6
50 179 Tax 2 Chohan 40 44 LHR Ghafoor

75 148 Consulting 6 Zahid 52 52 ISD Babar


179 tax 6

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:

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

10
FIRST NORMAL FORM (1NF)
Primary key

Accountant Skill Skill Proficiency Accountant Accountant Group No Group Group


No No Category No Name age City supervisor

21 113 Systems 3 Ali 55 52 ISD Babar

35 113 Systems 5 Daud 32 44 LHR Ghapfoor

35 179 Tax 1 Daud 32 44 LHR Ghafoor

35 204 Audit 6 Daud 32 44 LHR Ghafoor

50 179 Tax 2 Chohan 40 44 LHR Ghafoor

75 148 Consulting 6 Zahid 52 52 ISD Babar

75 179 tax 6 Zahid 52 52 ISD Babar

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

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.

SALAM University, Kabul


Abasyn University, Peshawar

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.

SALAM University, Kabul


Abasyn University, Peshawar

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.

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

14 SECOND NORMAL FORM (2NF)


Primary key

Accountant Proficiency Accountant Accountant Group No Group Group


No No Name age City supervisor

21 3 Ali 55 52 ISD Babar

35 5 Daud 33 44 LHR Ghapfoor


1
6
50 2 Chohan 40 44 LHR Ghafoor

75 6 Zahid 52 52 ISD Babar


6

Similarly another relation skill can be created in which all


fields are fully depended on the primary key as follows:

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

15 SECOND NORMAL FORM (2NF)


Primary key

Skill No Skill Category

113 Systems

113 Systems
179 Tax
204 Audit
179 Tax

148 Consulting tax


179

The attributes proficiency in 1NF relation was fully dependent on the


whole primary key. The proficiency requires to know the accountant
number and skill number. The third relation will be created as follows:

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

16 SECOND NORMAL FORM (2NF)


Primary key

Accountant No Skill No Proficiency

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.

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

17 ANALYSIS OF SECOND NORMAL FORM (2NF)

• 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.

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

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 AB and BC then C is transitive
dependency on A via B provided that A is not functionally dependent on B or C.

• Suppose there is a relation BOOK as follows:

• BOOK(BookID, BookDescription, CategoryID, CategoryDescription)

• We can wirte :

• BookID,  CategoryID, CategoryID  CategoryDescription)

• 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.

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

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:

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

20
THIRD NORMAL FORM (3NF)
Primary key

Accountant No Accountant Name Accountant age Group No

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:

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

21
THIRD NORMAL FORM (3NF)
Primary key

Group No Group City Group supervisor

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.

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

22
THIRD NORMAL FORM (3NF)
Primary key

Skill No Skill Category

113 Systems

179 Tax

204 Audit

148 Consulting tax

The proficiency table in 2NF also contains no attributes which is depending


on non-key attribute. It is already in third normal form and will be used
without any further change.

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

23
THIRD NORMAL FORM (3NF)
Primary key

Accountant No Skill No Proficiency

21 113 3

35 113 5

35 179 1

35 204 6

50 179 2

77 148 6

77 179 6

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

24
BOYCE CODD NORMAL FORM (BCNF)
Primary key

Project ID Part ID Quantity Used Part Name

101 P01 20 CD_R

112 P05 6 Zip disk

194 P01 12 CD-R

194 P02 1 Box floppy disks

194 P05 3 Zip disk


A relation is in Boyce - Codd normal from if and only if every determinant is
a candidate key. It can be checked by identifying all determinants and then
making sure that all these determinates are candidate key. BCNF is a stronger
from of third normal form. A relation in BCNF is also in third normal from.
But a relation in 3NF may not be in BCNF.

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

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.

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

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.

• In order to convert this relation to BCNF, all functional dependencies must


be removed which have a determinant that is not a candidate key . The
result is as follows:
Primary key Primary key

Part ID Part Name Project ID Part ID Quantity


Used
P01 CD_R
101 P01 20
P02 Box floppy disks
112 P05 6
P05 Zip disk
194 P01 12

194 P02 1

SALAM University, Kabul 194 P05 3


SALAM University, Kabul December 13, 2024

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

• A determines multiple values of C 100 Math Reading


• B and C are independent of each other. 100 Accounting Reading
• For example the following relation has 100 Math Tennis
multi-valued decencies:
100 Accounting Tennis

150 Economics Jogging

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

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

100 Accounting Tennis

150 Economics Jogging

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

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:

Student ID Subject Interest

100 Economics Reading

100 Economics Tennis

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

30
CONTI…
Similarly, if a student wants to drop a subject, all tuples containing that
particular subject hast to be deleted.

In order to eliminate these anomalies, multi-valued dependency should be


eliminated. It can be done by creating two relation. Each relation will contain
data for only one multi valued attribute. The resulting relation do not have
anomalies.
Student ID Subject Student ID Interest

100 Math 100 Reading

100 Accounting 100 Tennis

150 Economics 150 Jogging

SALAM University, Kabul


31
FIFTH NORMAL FORM (5NF)
• Fifth normal form (5NF)

• 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.

• 5NF is also known as Project-join normal form (PJ/NF).

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

32
FIFTH NORMAL FORM (5NF)
SUBJECT LECTURER SEMESTER

Computer Anshika Semester 1


Computer John Semester 1
Math John Semester 1
Math Akash Semester 2
Chemistry Praveen Semester 1

SALAM University, Kabul


33
FIFTH NORMAL FORM (5NF)
• In the above table, John takes both Computer and Math class for Semester 1 but he
doesn't take Math class for Semester 2. In this case, combination of all these fields
required to identify a valid data.

• 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:

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

34 EXAMPLE OF FIFTH NORMAL FORM (5NF)

P1 P2 P3
SEMESTER SUBJECT SUBJECT LECTURER SEMSTER LECTURER

Semester 1 Computer Computer Anshika Semester 1 Anshika


Semester 1 Math Computer John Semester 1 John
Semester 1 Chemistry Math John Semester 1 John
Semester 2 Math Math Akash Semester 2 Akash

SALAM University, Kabul


35
SUMMARY
• A key is attribute or a set of attributes that uniquely identify a tuple in a
relation.
• The set of attributes which can uniquely identify a tuple is known as
Super Key.
• A primary key is an attribute or a combination of attributes that
uniquely identifies each row in a relation.
• A composite key is a key that consists of two or more attributes is know
as composite key.
• The alternet keys that are not selected as primary key are known as
alternate keys.

SALAM University, Kabul


SALAM University, Kabul December 13, 2024

36

THE END

SALAM University, Kabul

You might also like