NORMALIZATION PRESENTED BY SANJIT PRASAD
NORMALIZATION
PRESENTED BY
SANJIT PRASAD
Roadmap
Introduction
Terminology used in Normalization(Basic Tools)
Different Normal Forms
1.INTRODUCTION
Basics:DATA - any fact that can be recorded.eg-textDATABASE - Collection of all related data. Eg- collec- tion of video files,images etc.
11
SO WHY WE NEED TO NORMALIZE THE RELATIONS or TABLES
• To eliminate redundant data
• To provide accuracy
• To make database faster and efficient
To remove updation, insertion, deletion anomaly(deviation from the normal or common order or form or rule)
22
Explanation:
Example 1.
Wid Wname Aid Aname Asize
1 Raju 001 Burnpur 1 acres
2 Avay 002 Haldia 2 acres
(Table 1)
Say in the above table if you want to delete tupple 2 (say Avay leave the company, so we must delete his information from the table.).
33
Example 2
Wid Wname Aid Aname Asize
1 Raju 001 Burnpur 1 acre
2 Raju 002 Haldia 2 acre
3 Bimal 002 Haldia 2 acre
Say after analyzing by scientist they found the watchman Raju who works in Haldia that place is not 2 acre its 3 acre so modify it.
Wid Wname Aid Aname Asize 1 Raju 001 Burnpur 1
acre 2 Raju 002 Haldia 3
acre 3 Bimal 002 Haldia 2
acre
(UPDATION ANOMALY) (SO remove this kind of problem we need normalization).
44
44Example 2
Wid Wname Aid Aname Asize
1 Raju 001 Burnpur 1 acre
2 Raju 002 Haldia 2 acre
3 Bimal 002 Haldia 2 acre
Say after analyzing by scientist they found the watchman Raju who works in Haldia that place is not 2 acre its 3 acre so modify it.
Wid Wname Aid Aname Asize 1 Raju 001 Burnpur 1
acre 2 Raju 002 Haldia 3
acre 3 Bimal 002 Haldia 2
acre
(UPDATION ANOMALY) (SO remove this kind of problem we need normalization).
(a)Functional Dependency (F.D)
• Mathematical expression In a given relation R, If X and Y are the set of attributes and if Y is functionally depend on X then i.e. XY and t1,t2 are two tuples in relation R, Then If t1[X] = t2[X] Then t1[Y] = t2[Y] Lets take an example
2.Terminology Used In Normalization2.Terminology Used In Normalization55
(a)Functional Dependency (F.D)
• Mathematical expression In a given relation R, If X and Y are the set of attributes and if Y is functionally depend on X then i.e. XY and t1,t2 are two tuples in relation R, Then If t1[X] = t2[X] Then t1[Y] = t2[Y] Lets take an example
In the above example for the same tuple we got same value, if we got different values then there is no functional dependency. So there are following functional dependencies SidSname Sidfname Sidmname
55
(b)Axioms of FD
(1)If X ⊇Y then X Y. [REFLEXIVE RULE] [Note: - X X is called trivial dependency] (2)If XY and WZ then WXYZ. [AUGMENTATION RULE] (3)If XY and YZ then XZ [TRANSITIVE RULE] (4)If XY and XZ then XYZ [UNION RULE] (5) If XYZ then XY and XZ [DECOMPOSITION RULE]
66
(c) Attribute Closure• Attribute closure means set of attributes uniquely determined by a single
attribute
Say R(A,B,C,D) be a relation and FDs are
AB
BC
CD
Then
Closure of A i.e. A+ = A, B, C, D
Closure of B = B, C, D
Closure of C = C, D
Closure of D = D
77
Example:
AC
AB
CD
EF
FDG
Find A+, AE+?
Solution:- A+=A,B,C,D
AE+=A, E, C, B, D, F, G
88
(d)Superkey Set of attribute which uniquely determine all the attributes of the table
99
(e)Candidate Key(e)Candidate Key Minimal set of attributes which uniquely determines all other attributesMinimal set of attributes which uniquely determines all other attributes
R(A,B,C,D,E)
And FDS are AB,BC,CD,BD,BDE,BDA
Find candidate key for the relation R?
Solution: B+=A,B,C,D,E (only candidate key)
[Note: If you add any attribute in Candidate Key it produce a Super Key]
In the above problem BD may a Super Key, As BD+=A,B,C,D,E
1010
Calculation Of number Of key in a relationCalculation Of number Of key in a relationALGORITHM
(I)Find at least one candidate key.
(II)Check if there is any replacement for that candidate key (part of CKey) or not
If replacement is there then replace that Ckey part with that domain
And repeat the step II until it is not false
(III)Count the number of Candidate Key
1111
Example:
R (A, B, C, D, E, F, G, H)
FD’s are CHG, ABC, BCFG, EA, and FEG
Find the number of candidate key for the relation R? [Gate 2013]
Solution:
Find at least one Candidate key
Say BD+=A,B,C,D,E,F,G (1st Candidate Key)
*Now in FD ABC there is replacement for B determined by A hence
AD is 2nd candidate key.
*in EA there is replacement for A also, hence ED is 3rd Candidate key.
*in FEG there is replacement for E , hence FD is 4th Candidate key.
Now none of the Candidate Key attribute has to be replaced so Total number of Candidate key is 4.
1212
3.NORMAL FORMS3.NORMAL FORMS1313
1NF (First Normal Form)1NF (First Normal Form) A table is in 1NF if every attribute of the table is atomicA table is in 1NF if every attribute of the table is atomic
1414
ATOMIC ATTRIBUTE VS NON ATOMIC ATTRIBUTE
Atomic attributes are those attribute having single value in their table.
Example employee_id, employee_name, salary etc.
Non atomic attributes are multivalued attributes.
Exampleaddress, phone_number.
In terms of DBMS
(Note: - By default we are provided 1NF)
1515
2NF(Second Normal Form)2NF(Second Normal Form) A table is in 2nf iff (i) It is in 1 NFA table is in 2nf iff (i) It is in 1 NF
(ii)No partial dependency(ii)No partial dependency
SHORT TRICK: Whenever Candidate key has single attribute then there is no partial dependency so directly say it is in 2NF.
1616
Example:
R (A, B, C, D)
AB, BD, CA, AC
Check whether it is in 2NF or not?
Solution find all possible candidate key
Hence, A,C are Candidate Keys.
So here no partial dependency present so table is in 2NF.
1717
3NF(Third Normal Form)3NF(Third Normal Form)A table is in 3NF if and only if
Non trivial means
Note (1): If a table is in 3NF then it must be in 2NF.
Note (2): Transitive Dependency is a 3NF error but Partial Dependency is 2NF error.
1818
Example:
R(A,B,C,D)
AB,BC,CD
Check it is 3NF or not?
Solution:
At FD BC , neither B is a super key nor C is prime attribute and hence 3NF error ,
Thus relation R is not in 3NF.
1919
4.BCNF(Boyce Codd Normal Form)4.BCNF(Boyce Codd Normal Form)
For every non trivial dependency XFor every non trivial dependency Xa , X is a Super Keya , X is a Super Key
Example:
R(A,B,C,D)
ABC,CD,DA
Check for BCNF.
Solution:
HENCE BCNF.
2020
4NF(Fourth Normal Form)4NF(Fourth Normal Form)
5NF(Fifth Normal Form)5NF(Fifth Normal Form)Relation R is in 5NF if
2121
ADVANCED DATA BASE MANAGEMENT SYSTEM by A.HofferADVANCED DATA BASE MANAGEMENT SYSTEM by A.Hoffer
AN INTRODUCTION TO DATABASE SYSTEM by C.J.DateAN INTRODUCTION TO DATABASE SYSTEM by C.J.Date