0% found this document useful (0 votes)
15 views45 pages

Chapter 9 NORMALIZATION 1

Chapter 9 discusses normalization in databases, focusing on anomalies such as update, delete, and insert anomalies, and the importance of functional dependencies. It outlines the various normal forms (1NF, 2NF, 3NF, BCNF, 4NF, and 5NF) and their conditions for ensuring data integrity and reducing redundancy. The chapter also covers Armstrong's axioms, decomposition, and lossless decomposition to achieve optimal database design.

Uploaded by

readprogramming
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)
15 views45 pages

Chapter 9 NORMALIZATION 1

Chapter 9 discusses normalization in databases, focusing on anomalies such as update, delete, and insert anomalies, and the importance of functional dependencies. It outlines the various normal forms (1NF, 2NF, 3NF, BCNF, 4NF, and 5NF) and their conditions for ensuring data integrity and reducing redundancy. The chapter also covers Armstrong's axioms, decomposition, and lossless decomposition to achieve optimal database design.

Uploaded by

readprogramming
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/ 45

Chapter 9

Normalization
Sonik Shrestha
M.Sc Information System
NTNU, TRONDHEIM, NORWAY
ANOMALIES
• Types
– Update Anomalies
– Delete Anomalies and
– Insert Anomalies
Update anamoly
• Update Anomaly arises when there is duplication of data. So when data is
updated at one place, but not at another places, the database table is rendered
ambiguous. Consider the following Order table.
Delete Anamoly
• Delete Anomaly occurs when certain field information is lost due to deletion of
other fields.
Insert Anamoly
• Insert Anomaly is when we are unable to insert a piece of information unless
some other piece is also present .
FUNCTIONAL DEPENDENCIES
• A functional dependency occurs when one
attribute in a relation uniquely determines
another attribute. This can be written A -> B
which would be the same as stating :
– "B is functionally dependent upon A."
– “A functionally determines B.”
Contd..
A B C D
a1 b1 c1 d1
a1 b2 c1 d2
a2 b2 c2 d2
a2 b2 c2 d3
a3 b3 c2 d4

a1b1 AB (incorrect: since a1 determines 2 values of B)


a1b2

a1c1 AC (Correct )


a2c2 so, we say A functionally determines C
a3c2
Contd..
• Example
NAME ROLL CGPA
Ram R1 3.2
Shyam R2 3.3
Hari R3 3.4
Ram R4 3.5

• What is CGPA of Ram??


Types of Functional Dependencies
• Full Functional Dependencies
• Partial Functional Dependencies
• Transitive Functional Dependencies
• Trivial Functional Dependencies
Transitive F.D.
• Follows Transitive Rule
- If A=B and B=C, then A=C
• Transitive dependencies occur when there is
an indirect relationship that causes a
functional dependency.
• For example, “A -> C” is a transitive
dependency when it is true only because both
“A -> B” and “B -> C” are true.
Trivial F.D
• A trivial functional dependency occurs when you describe a
functional dependency of an attribute on a collection of attributes
that includes the original attribute. This type of functional
dependency is called trivial because it can be derived from common
sense. It is obvious that if you already know the value of B, then the
value of B can be uniquely determined by that knowledge.
• Another Def. : If Y is a subset of X, Then XY
• Examples:
– {A,B}B
– AA
Full Functional Dependencies
• For XY, If Y can not be determined by any of
the proper subset of X, Then Y is fully
Functional Dependent upon X (or X Fully
Determines Y).
• Example: XY and abc are attributes of X and
d is attribute of Y, then if
– bcd, cd, ad, etc cannot be true
– abcd, should only be true.
Partial Functional Dependencies
• For X-->Y, if Y can be determined by any of
proper subset of X, Then Y is partially
functional dependent on X.
• Example: XY and abc are attributes of X and
d is attribute of Y, then if
– bcd, cd, ad, etc (if atleast one is true)
Importance of Dependencies
• For a table to be in second normal form (2NF), there must
be no case of a non-prime attribute in the table that is
functionally dependendent upon a subset of a candidate
key

• For a table to be in third normal form (3NF), every non-


prime attribute must have a non-transitive functional
dependency on every candidate key.
Contd..

• For a table to be in Boyce-Codd Normal Form (BCNF), every


functional dependency (other than trivial dependencies)
must be on a superkey.

• For a table to be in fourth normal form (4NF), it must have


no multivalued dependencies.
Armstrong’s Axioms
• Reflexivity rule: If A is a set of attributes, and B is a set of
attributes that are completely contained in A, the A implies
B.
– If B is subset of A, then A implies B
• Augmentation rule: If A implies B, and C is a set of
attributes, then AC implies BC.
– If, AB and C is set of Attributes, THEN, ACBC
• Transitivity rule: If A implies B and B implies C, then A
implies C.
– If, AB and BC, THEN, AC
Contd..
• These can be simplified if we also use:
• Union rule: If A implies B and A implies C, the A implies BC.
– if ABAND AC, THEN ABC
• Decomposition rule: If A implies BC then A implies B and A
implies C.
– If ABC, THEN AB and AC
• Pseudotransitivity rule: If A implies B and CB implies D,
then AC implies D.
Decomposition
• The bad design suggests that we should
decompose a relation schema that has many
attributes into several schemas with fewer
attributes. Careless decomposition, however,
may lead to another form of bad design.
Normalization
• Normalization is the process of taking data from a
problem and reducing it to a set of relations while
ensuring data integrity and eliminating data
redundancy
– Data integrity - all of the data in the database are
consistent, and satisfy all integrity constraints.
– Data redundancy – if data in the database can be
found in two different locations (direct redundancy)
or if data can be calculated from other data items
(indirect redundancy) then the data is said to contain
redundancy.
First Normal Form (1NF)
• Should have a unique Key.
• There are no duplicated columns in a table.
• Each cell has atomic value.(single value)
1NF Example
• ONE MORE EXAMPLE
STUD_ID NAME CITY CONTACT1 CONTACT2 CONTACT3
1 RAM KTM 9841 4444 01685
2 SHYAM PKR 9851
3 HARI BRT 9844 01555
1NF contd..
NAME AGE HOBBIES
RAM 20 FOOTBALL, MUSIC
SHYAM 21 DANCE
HARI 20 BASKETBALL
SECOND NORMAL FORM (2NF)
• TO BE IN SECOND NORMAL FORM,
– IT SHOULD SATISFY 1NF, AND
– ANY NON-KEY FIELD SHOULD BE FULLY
DEPENDENT ON THE ENTIRE PRIMARY KEY.
EXAMPLE
• Events Table
Course_id Date courseTitle Seats Room

Sql 25/08/2015 Intro to sql 10 1

Sql 20/06/2015 Intro to sql 12 2

Sql 20/07/2015 Intro to sql 15 3


– Key=course_id+date (composite key)
–DbSeats and Room are
20/05/2015 fully dependent
Database 8 on
4 Key

– courseTitle is only dependent on course_id


Contd..
• What if someone changes SQL to ASP
Course_id Date courseTitle Seats Room

Sql 25/08/2015 Intro to sql 10 1

ASP 20/06/2015 Intro to sql 12 2

Sql 20/07/2015 Intro to sql 15 3

Db 20/05/2015 Database 8 4
After applying 2NF
Course_id Date Seats Room

Sql 25/08/2015 10 1

ASP 20/06/2015 12 2

Sql 20/07/2015 15 3

Db 20/05/2015 8 4
THIRD NORMAL FORM (3NF)
• Conditions for 3NF
– Should be in 2NF and
– No-non key fields are dependent on another non
key field
Contd…
Event_id Course_id Date Available Room Capacity
1 Sql 20/08/2015 5 14 30
2 Asp 20/07/2015 2 15 22
3 Sql 20/06/2015 4 12 18
4 Db 20/09/2014 6 10 20
• Primary Key – Event_id
• Capacity is dependent on Room
3NF contd…
• So, to convert it to 3NF form
Event_id Course_id Date Available Room

1 Sql 20/08/2015 5 14

2 Asp 20/07/2015 2 15

3 Sql 20/06/2015 4 12

4 Db 20/09/2014 6 10

Room Capacity
14 30
15 22
12 18
10 20
One more example

ID Product_ID Unit Price Quantity Total

1 P1 2 6 12

2 P2 3 5 115

3 P3 4 4 16

4 P4 5 3 15

Total is dependent on unit price and quantity


BCNF
• Boyce Codd Normal Form
• Normally 3NF is already in BCNF
• But there are conditions when the table is in 3NF
and not in BCNF
– When a relation has more than one candidate key,
anomalies may result even though the relation is in 3NF.
– 3NF does not deal satisfactorily with the case of a
relation with overlapping candidate keys
– i.e. composite candidate keys with at least one attribute
in common.
Conditions for BCNF
• It should be in 1NF, 2NF, 3NF form.
• A relation is in BCNF is, and only if, every
determinant is a candidate key.
– A determinant is any attribute (simple or composite) on which some
other attribute is fully functionally dependent.
Example
• Consider the following table
Author Nationality Book title Genre No. of pages

Ram Nepali Ramayan Mythological 1500

William English Romoe n Juliet Romantic 100


Shakespeare

Chetan Bhagat Indian 3 Idiots Comedy 200

Paulo coelho Brazilian The Alchemist Inspirational 250


– Author->Nationality
– Book title->Genre, no of pages
– Candidate key = {author, book title}
contd
Author Book title
Author Nationality
Ram Ramayan
Ram Nepali
William Romoe n Juliet
William Shakespeare English Shakespeare
Chetan Bhagat 3 Idiots
Chetan Bhagat Indian
Paulo coelho Brazilian Paulo coelho The Alchemist

Book title Genre No. of pages


Ramayan Mythological 1500
Romoe n Juliet Romantic 100
3 Idiots Comedy 200
The Alchemist Inspirational 250
Fourth Normal Form (4NF)
• Conditions
– R is already in 3NF or BCNF.
– If it contains no non-trivial multi-valued dependencies

–OR
– If a Relation(table) R has multi-valued dependencies (X->-
>Y), then multi-valued dependency should be trivial or X is
a super key for relation R.
• So What is Multi valued Dependencies (MVD)
Multi Value Dependency
• Remember 1NF form
Emp_name Project_name Dependent_name

Hari X Krishna
Hari Y Radha
Hari X Radhan
Hari Y Krishna

Emp_name:Project_name (1:N)
Emp_name:Dependent_name (1:N)
Emp_nameProject_name
Emp_nameDependent_name
MVD contd..
• Types of Multi Value Dependency
– Trivial
• If XY, (Y is subset of X)
• And (XuY=R)
• Else NON-Trivial
4NF Example
Employee_name Project_name
Smith X
Smith Y

Employee project Table

Employee_name Dependent_name
Smith Krishna
Smith Radha

Employee dependent Table


FIFTH Normal Form (5NF)
 A Relation is said to be in 5NF if:
– It is already in 4NF and
– It can not be further non-loss decomposed

 So What is lossless decomposition??


Loss Less Decomposition
• Let’s assume R is decomposed to R1 and R2
• R’= R1+R2 (natural join )
• If R=R’, then we say, there is a loss less
decomposition
5NF Example

• The table still contains redundant data. So, lets try decomposing this table
Contd..
• The Redundancy is minimized as much as possible.

• Let us join P1 and P2


Contd..
• Further original table P3
Contd..
• Now joining p1,p2 and p3

• We Get the original Table

You might also like