Post on 08-Jul-2018
8/19/2019 Normalization 450
1/44
BordoloiBordoloi
Database Design: NormalizationDatabase Design: Normalization
Dr. Bijoy BordoloiDr. Bijoy Bordoloi
8/19/2019 Normalization 450
2/44
8/19/2019 Normalization 450
3/44
Bordoloi
Results of NormalizationResults of Normalization
• Removes the following modificationRemoves the following modificationanomaliesanomalies (integrity errors with the(integrity errors with the
data!asedata!ase
" #nsertion#nsertion " DeletionDeletion
" $pdate$pdate
8/19/2019 Normalization 450
4/44
Bordoloi
%N&'%#)*%N&'%#)*
• #nsertion#nsertion
" inserting one fact in the data!ase re+uires nowledgeinserting one fact in the data!ase re+uires nowledge
of other facts unrelated to the fact !eing insertedof other facts unrelated to the fact !eing inserted• DeletionDeletion
" Deleting one fact from the data!ase causes loss ofDeleting one fact from the data!ase causes loss ofother unrelated data from the data!aseother unrelated data from the data!ase
• $pdate$pdate " $pdating the values of one fact re+uires multiple$pdating the values of one fact re+uires multiple
changes to the data!asechanges to the data!ase
8/19/2019 Normalization 450
5/44
Bordoloi
%N&'%#)* )-%'P)*%N&'%#)* )-%'P)*
T%B). /&$R*)T%B). /&$R*)/&$R*)0/&$R*)0 *)/T#&N0*)/T#&N0 /1N%')/1N%')
/#*234/#*234 567567 Data!ase DesignData!ase Design
/#*234/#*234 568568 Data!ase DesignData!ase Design
/#*265/#*265 567567 &racle 9orms&racle 9orms
/#*234/#*234 564564 Data!ase DesignData!ase Design
8/19/2019 Normalization 450
6/44
Bordoloi
%N&'%#)* )-%'P)*%N&'%#)* )-%'P)*
##nsertion.nsertion.*uppose our university has approved a new*uppose our university has approved a new
course called /#*238. *: ; P
/&$R*)0/&$R*)0 *)/T#&N0*)/T#&N0 /1N%')/1N%')
/#*234/#*234 567567 Data!ase DesignData!ase Design
/#*234/#*234 568568 Data!ase DesignData!ase Design
/#*265/#*265 567567 &racle 9orms&racle 9orms
/#*234/#*234 564564 Data!ase DesignData!ase Design
8/19/2019 Normalization 450
7/44
Bordoloi
%N&'%#)* )-%'P)*%N&'%#)* )-%'P)*
Deletion.Deletion.
*uppose not enough students enrolled for the*uppose not enough students enrolled for the
course /#*265 which had only one section 567= *o,course /#*265 which had only one section 567= *o,
the school decided to drop this section and delete thethe school decided to drop this section and delete thesection0 567 for /#*265 from the ta!le /&$R*)=section0 567 for /#*265 from the ta!le /&$R*)=
But then, what other relevant info also got deleted inBut then, what other relevant info also got deleted in
the process>the process>/&$R*)0/&$R*)0 *)/T#&N0*)/T#&N0 /1N%')/1N%')
/#*234/#*234 567567 Data!ase DesignData!ase Design
/#*234/#*234 568568 Data!ase DesignData!ase Design
/#*265/#*265 567567 &racle 9orms&racle 9orms
/#*234/#*234 564564 Data!ase DesignData!ase Design
8/19/2019 Normalization 450
8/44
Bordoloi
%N&'%#)* )-%'P)*%N&'%#)* )-%'P)*
$pdate.$pdate.
*uppose the course name (/1Name for /#**uppose the course name (/1Name for /#*
234 got changed to Data!ase 'anagement= ?ow234 got changed to Data!ase 'anagement= ?ow
many times do you have to mae this change in themany times do you have to mae this change in the/&$R*) ta!le in its current form>/&$R*) ta!le in its current form>
/&$R*)0/&$R*)0 *)/T#&N0*)/T#&N0 /1N%')/1N%')
/#*234/#*234 567567 Data!ase DesignData!ase Design
/#*234/#*234 568568 Data!ase DesignData!ase Design
/#*265/#*265 567567 &racle 9orms&racle 9orms
/#*234/#*234 564564 Data!ase DesignData!ase Design
8/19/2019 Normalization 450
9/44
8/19/2019 Normalization 450
10/44
Bordoloi
N&R'% 9&R'* N&R'% 9&R'*
C N9C N9
7N97N9
8N98N9
• B/N9 (Boyce/odd Normal 9ormB/N9 (Boyce/odd Normal 9orm
• 4N94N9• 2N92N9
• DK (Domain-Key) NF DK (Domain-Key) NF
8/19/2019 Normalization 450
11/44
BordoloiBordoloi
E
9irst Normal 9orm(CN99irst Normal 9orm(CN9
*econd Normal 9orm(7N9*econd Normal 9orm(7N9Third Normal 9orm(8N9Third Normal 9orm(8N9
9ourth Normal 9orm(4N99ourth Normal 9orm(4N9
9ifth Normal 9orm(2N99ifth Normal 9orm(2N9
Boyce/odd Normal 9orm(B/N9Boyce/odd Normal 9orm(B/N9
Domain
8/19/2019 Normalization 450
12/44
Bordoloi
9unctional Dependency9unctional Dependency
• Relationship !etween columns - and Relationship !etween columns - and such that, given the value of -, one cansuch that, given the value of -, one can
determinedetermine the value of = Gritten as - the value of = Gritten as - i.e., for a given value of X we can obtain (ori.e., for a given value of X we can obtain (or
look u) a secific value of X look u) a secific value of X
• - is called the- is called the determinant determinant of of
• is said to !e is said to !e functionally deendent functionally deendent on on
8/19/2019 Normalization 450
13/44
Bordoloi
9unctional Dependency9unctional Dependency• )Hample)Hample
" *&/1*)/1NBR )'P1N')*&/1*)/1NBR )'P1N')
*&/1*)/1NBR *&/1*)/1NBR )'P1N'))'P1N')
&ne and only one )'P1N') for a specific *&/1*)/1NBR &ne and only one )'P1N') for a specific *&/1*)/1NBR
*&/1*)/1NBR is the*&/1*)/1NBR is the determinant determinant of )'P1N')of )'P1N') )'P1N') is functionally)'P1N') is functionally deendent deendent on *&/1*)/1NBR on *&/1*)/1NBR
8/19/2019 Normalization 450
14/44
Bordoloi
CN9
% ta!le is in CN9 if there are no repeating groups in
the ta!le= #n other words, a ta!le is in CN9 if all non
ey fields are functionally dependent on the primary
ey (PF= That is, for each given value of PF, wealways get only one value of the noney field(s=
#s the following ta!le /&$R*) in CN9>
/&$R*)0/&$R*)0 *)/T#&N0*)/T#&N0 /1N%')/1N%')/#*234/#*234 567567 Data!ase DesignData!ase Design
/#*234/#*234 568568 Data!ase DesignData!ase Design
/#*265/#*265 567567 &racle 9orms&racle 9orms
/#*234/#*234 564564 Data!ase DesignData!ase Design
/ourse
8/19/2019 Normalization 450
15/44
8/19/2019 Normalization 450
16/44
Bordoloi
Partial DependencyPartial Dependency
• &ccurs when a column in a ta!le only&ccurs when a column in a ta!le only
depends on part of a concatenated eydepends on part of a concatenated ey
/&$R*)/&$R*) ((/&$R*)0 J *)/T#&N0/&$R*)0 J *)/T#&N0, /N%'), /N%')
)Hample)Hample
8/19/2019 Normalization 450
17/44
Bordoloi
7N97N9
• /1Name only depends upon the/1Name only depends upon the/ourse0 not the *ection0= #t is partially/ourse0 not the *ection0= #t is partially
dependent upon the primary ey=dependent upon the primary ey=
• % ta!le is in 7N9 if it is in CN9 and has% ta!le is in 7N9 if it is in CN9 and has
no partial dependencies=no partial dependencies=
8/19/2019 Normalization 450
18/44
Bordoloi
7N97N9
• ?ow do you resolve partial dependency>?ow do you resolve partial dependency>
• Decompose the pro!lematic ta!le intoDecompose the pro!lematic ta!le into
smaller ta!les=smaller ta!les=• 'ust !e a @losslessA decomposition='ust !e a @losslessA decomposition=
That is, you must !e a!le to put theThat is, you must !e a!le to put the
decomposed ta!les !ac together again todecomposed ta!les !ac together again toarrive at the original information=arrive at the original information=• Remem!erRemem!er Foreign Keys Foreign KeysKK
8/19/2019 Normalization 450
19/44
Bordoloi
7N97N9
/&$R*)0/&$R*)0 /1N%')/1N%')
/#*234/#*234 Data!ase DesignData!ase Design
/#*265/#*265 &racle 9orms&racle 9orms
!"#$%&' !"#$%&' *)/T#&N0*)/T#&N0
/#*234/#*234 567567
/#*234/#*234 568568
/#*234/#*234 564564/#*265/#*265 567567
/&$R*)/&$R*)
&99)R)D1/&$R*)&99)R)D1/&$R*)
8/19/2019 Normalization 450
20/44
Bordoloi
7N97N9
• %re the two (decomposed ta!les /&$R*) and%re the two (decomposed ta!les /&$R*) and&99))R)D1/&$R*) are 7N9>&99))R)D1/&$R*) are 7N9>
• Do these two ta!les have any modificationDo these two ta!les have any modificationanomalies>anomalies> " /an you now readily enter the info that a new approved/an you now readily enter the info that a new approved
course /#*238>course /#*238>
" /an you now delete the section0 567 for /#*265/an you now delete the section0 567 for /#*265without losing the info tat /#*265 eHists>without losing the info tat /#*265 eHists>
" ?ow many times do you have to change the name of a?ow many times do you have to change the name of agiven course>given course>
8/19/2019 Normalization 450
21/44
Bordoloi
Transitive DependencyTransitive DependencyTa!le. *tudentDorm9eeTa!le. *tudentDorm9ee
*#D*#D D&R'D&R' 9))9))
C5CC5C &racle&racle C555C555
C57C57 &racle&racle C555C555
C58C58 DB7DB7 L55L55
C54C54 DB7DB7 L55L55
C52C52 *y!ase*y!ase 255255
8/19/2019 Normalization 450
22/44
Bordoloi
Transitive DependencyTransitive Dependency
• #s the ta!le *tudentDorm9ee in 7N9>#s the ta!le *tudentDorm9ee in 7N9>
• Does this ta!le have any modification anomalies>Does this ta!le have any modification anomalies>
" #nsertion>#nsertion>
" Deletion>Deletion>
" $pdate>$pdate>
8/19/2019 Normalization 450
23/44
Bordoloi
Transitive DependencyTransitive Dependency
•&ccurs when a noney attri!ute is functionally depe&ccurs when a noney attri!ute is functionally depen
one or more noney attri!utes=one or more noney attri!utes=
)Hample.)Hample. ?&$*#NM (?&$*#NM (*#D*#D, D&R', 9)), D&R', 9))
PR#'%R F). *#DPR#'%R F). *#D9$N/T#&N% D)P)ND)N/#)*.9$N/T#&N% D)P)ND)N/#)*.
*#D*#D B$#D#NMB$#D#NM
*#D*#D 9))9))
D&R'D&R'
9))9))
• % ta!le is in 8N9 if it is in 7N9 and has no transitive% ta!le is in 8N9 if it is in 7N9 and has no transitive
dependenciesdependencies
8/19/2019 Normalization 450
24/44
Bordoloi
8N98N9
• Besides *#D, 9)) is alsoBesides *#D, 9)) is alsofunctionally dependent on D&R'functionally dependent on D&R'
which is a noney attri!ute=which is a noney attri!ute=
• % ta!le is in 8N9 if it is in 7N9 and% ta!le is in 8N9 if it is in 7N9 and
has no transitive Dependencies=has no transitive Dependencies=
8/19/2019 Normalization 450
25/44
8/19/2019 Normalization 450
26/44
Bordoloi
8N98N9
D&R'D&R' 9))9))
&racle&racle C555C555
DB7DB7 L55L55
*y!ase*y!ase 255255
*#D*#D D&R'D&R'
C5CC5C &racle&racleC57C57 &racle&racle
C58C58 DB7DB7
C54C54 DB7DB7
C52C52 *y!ase*y!ase
D&'19))D&'19))
*T$D)NT1D&R'*T$D)NT1D&R'
8/19/2019 Normalization 450
27/44
Bordoloi
8N98N9
• %re the two (decomposed ta!les%re the two (decomposed ta!les
*T$D)NT1D&R' and D&R'19)) in*T$D)NT1D&R' and D&R'19)) in
7N9>7N9>• %re they in 8N9>%re they in 8N9>
• Do these two ta!les have any modificationDo these two ta!les have any modification
anomalies>anomalies>
8/19/2019 Normalization 450
28/44
Bordoloi
Data Analyst’s OathData Analyst’s Oath
EVERY NON-EY !O"#$N %N AEVERY NON-EY !O"#$N %N A&AB"E $#'& BE&AB"E $#'& BE FUNCTIONALLYFUNCTIONALLY
DEENDENT DEENDENT #(ON &)E#(ON &)E ENTI!E ENTI!E
EY ANDEY AND NOT"IN# NOT"IN# B#& &)E EY*B#& &)E EY*
& h l
8/19/2019 Normalization 450
29/44
Bordoloi
&ther Normal 9orms&ther Normal 9orms
• There are additional normal forms which do not often occurThere are additional normal forms which do not often occur
in actual practice= ?owever, these situationsin actual practice= ?owever, these situations cancan occur inoccur in practice so it is necessary to understand them= These are. practice so it is necessary to understand them= These are.
" Boyce/odd Normal 9ormBoyce/odd Normal 9orm
" 9ourth Normal 9orm9ourth Normal 9orm
" 9ifth Normal 9orm9ifth Normal 9orm• Ge will deal with these normal forms if time allows= ouGe will deal with these normal forms if time allows= ou
must, however, fully understand Cmust, however, fully understand C*T*T through 8through 8RDRD N9= N9=
• Domain
8/19/2019 Normalization 450
30/44
BordoloiBordoloi
E
9irst Normal 9orm(CN99irst Normal 9orm(CN9
*econd Normal 9orm(7N9*econd Normal 9orm(7N9Third Normal 9orm(8N9Third Normal 9orm(8N9
9ourth Normal 9orm(4N99ourth Normal 9orm(4N9
9ifth Normal 9orm(2N99ifth Normal 9orm(2N9
Boyce/odd Normal 9orm(B/N9Boyce/odd Normal 9orm(B/N9
Domain
8/19/2019 Normalization 450
31/44
Bordoloi
Normal 9orms Normal 9orms
" 9irst Normal 9orm9irst Normal 9orm
• No repeating groups in ta!les No repeating groups in ta!les
" *econd Normal 9orm*econd Normal 9orm
• Ta!le is CTa!le is Cstst normal form and no partial eynormal form and no partial ey
dependenciesdependencies
" Third Normal 9ormThird Normal 9orm
• Ta!le is in 7Ta!le is in 7ndnd normal form and has nonormal form and has no
transitive dependenciestransitive dependencies
8/19/2019 Normalization 450
32/44
Bordoloi
Normal 9orms Normal 9orms
" Boyce/odd Normal 9ormBoyce/odd Normal 9orm
• )very determinant of a noney attri!ute is a candidate ey)very determinant of a noney attri!ute is a candidate ey
" 9ourth Normal 9orm9ourth Normal 9orm
• % ta!le has no multivalued dependencies% ta!le has no multivalued dependencies
" 9ifth Normal 9orm9ifth Normal 9orm
• There are no lossey Ioins !etween two or more ta!lesThere are no lossey Ioins !etween two or more ta!les
*ample $ser ie*ample $ser iew
8/19/2019 Normalization 450
33/44
Bordoloi
*ample $ser iew*ample $ser iew
8/19/2019 Normalization 450
34/44
Bordoloi
9irst Normal 9orm9irst Normal 9orm
•Remove the repeating groups and concatenate eysRemove the repeating groups and concatenate eysso that the original ta!le can !e recovered !y Ioiningso that the original ta!le can !e recovered !y Ioining
ta!lesta!les
ORD+NBR ORD +NBR ORD+D&EORD+D&E ,%(+ADR ,%(+ADR !#'+NBR !#'+NBR !#'+N$E!#'+N$E '&R+ADR '&R+ADR !&Y+ADR !&Y+ADR '&&+ADR '&&+ADR
'#B+&O&'#B+&O& R&+A$&R&+A$& &A&A &O&+A$&&O&+A$&
ORDORD
A$O#N&A$O#N&ORD+/&YORD+/&YORD+%&$+(R%!EORD+%&$+(R%!E%&$+D'!%&$+D'!%&$+NBR %&$ +NBR ORD+NBR ORD +NBR
ORD+%&$ORD+%&$
..
..
..
•Ghat pro!lems occur if the data!ase is stored using first normal form>Ghat pro!lems occur if the data!ase is stored using first normal form>
8/19/2019 Normalization 450
35/44
Bordoloi
*econd Normal 9orm*econd Normal 9orm
• %re these ta!les in 7%re these ta!les in 7ndnd
N9> N9>• #n other words, are there any partial dependencies>#n other words, are there any partial dependencies>
ORD+NBR ORD +NBR ORD+D&EORD+D&E ,%(+ADR ,%(+ADR !#'+NBR !#'+NBR !#'+N$E!#'+N$E '&R+ADR '&R+ADR !&Y+ADR !&Y+ADR '&&+ADR '&&+ADR
'#B+&O&'#B+&O& R&+A$&R&+A$& &A&A &O&+A$&&O&+A$&
ORDORD
A$O#N&A$O#N&ORD+/&YORD+/&YORD+%&$+(R%!EORD+%&$+(R%!E%&$+D'!%&$+D'!%&$+NBR %&$ +NBR ORD+NBR ORD +NBR
ORD+%&$ORD+%&$
..
..
..
* d N l 9*econd Normal 9orm
8/19/2019 Normalization 450
36/44
Bordoloi
*econd Normal 9orm*econd Normal 9orm• Remove any partial dependenciesRemove any partial dependencies
• %re there any%re there any transitive deendenciestransitive deendencies>>
ORD+NBR ORD+NBR ORD+D&EORD+D&E ,%(+ADR ,%(+ADR !#'+NBR !#'+NBR !#'+N$E!#'+N$E '&R+ADR '&R+ADR !&Y+ADR !&Y+ADR '&&+ADR '&&+ADR
'#B+&O&'#B+&O& R&+A$&R&+A$& &A&A &O&+A$&&O&+A$&
A$O#N&A$O#N&ORD+/&YORD+/&Y
ORD+%&$+(R%!EORD+%&$+(R%!E%&$+D'!%&$+D'!
IT$%N&! IT$%N&!O!D%N&!O!D%N&!
ORD+%&$ORD+%&$
ORDORD
%&$+NBR %&$+NBR
%&$%&$
Thi d N l 9Third Normal 9orm
8/19/2019 Normalization 450
37/44
Bordoloi
Third Normal 9ormThird Normal 9orm• Remove transitive dependenciesRemove transitive dependencies
ORD+NBR ORD+D&E
,%(+ADR
CU'%N&!
!#'+N$E '&R+ADR !&Y+ADR '&&+ADR
'#B+&O& R&+A$& &A &O&+A$&
A$O#N&ORD+/&Y
ORD+%&$+(R%!E%&$+D'!
IT$%N&!O!D%N&!
ORD+%&$
ORD
%&$+NBR
%&$
!#'+NBR
!#'
Third Normal 9ormThird Normal 9orm
8/19/2019 Normalization 450
38/44
Bordoloi
Third Normal 9ormThird Normal 9orm• Remove transitive dependenciesRemove transitive dependencies
ORD+NBR ORD+D&E
(I%AD!
CU'%N&!
!#'+N$E '&R+ADR
'#B+&O& R&+A$& &A &O&+A$&
A$O#N&ORD+/&Y
ORD+%&$+(R%!E%&$+D'!
IT$%N&!O!D%N&!
ORD+%&$
ORD
%&$+NBR
%&$
!#'+NBR
!#'
!%&Y '&A&E,%(
,%(
8/19/2019 Normalization 450
39/44
Bordoloi
D#*/$**#&ND#*/$**#&N
• #s the ta!le &rd1#tm in 8N9>#s the ta!le &rd1#tm in 8N9>
• ?ow a!out the ta!le &RD>?ow a!out the ta!le &RD>
8/19/2019 Normalization 450
40/44
Bordoloi
D#*/$**#&ND#*/$**#&N
• #s the ta!le &rd1#tm in 8N9> es=#s the ta!le &rd1#tm in 8N9> es= " There isThere is matematical deendencematematical deendence
!etween !etween &rd1:ty and %mount, N&T&rd1:ty and %mount, N&T
functional deendence functional deendence
• ?ow a!out the ta!le &RD> N&=?ow a!out the ta!le &RD> N&=
" #n this ta!le, however, there is#n this ta!le, however, there is functional functionaldeendencedeendence !etween the noney !etween the noneyattri!ultes Tot1%mt and (*u!1Tot Jattri!ultes Tot1%mt and (*u!1Tot J9rt1%mt J TaH9rt1%mt J TaH
8/19/2019 Normalization 450
41/44
Bordoloi
D)R#%B) D%T%D)R#%B) D%T%
• Rule of thum!. Do N&T include deriva!leRule of thum!. Do N&T include deriva!le
(computa!le data in the !aseline(computa!le data in the !aseline *ogical *ogical data!asedata!ase
design schemadesign schema
• ou may, selectively include some deriva!le dataou may, selectively include some deriva!le data
in your design, mainly to enhance the performancein your design, mainly to enhance the performance
of your application " which, however, is aof your application " which, however, is a ysical ysical data!ase design issue (which we will !e discussingdata!ase design issue (which we will !e discussing
soonsoon
Third Normal 9ormThird Normal 9orm
8/19/2019 Normalization 450
42/44
Bordoloi
Third Normal 9ormThird Normal 9orm• Remove transitive dependenciesRemove transitive dependencies
ORD+NBR ORD+D&E
,%(+ADR
CU'%N&!
!#'+N$E '&R+ADR
'#B+&O& R&+A$& &A &O&+A$&
A$O#N&ORD+/&Y
ORD+%&$+(R%!E%&$+D'!
IT$%N&!O!D%N&!
ORD+%&$
ORD
%&$+NBR
%&$
!#'+NBR
!#'
!%&Y '&A&E,%(
,%(
Deri0able
ields1
8/19/2019 Normalization 450
43/44
Bordoloi
:$)*T#&N:$)*T#&N
• *hould an )RD !e*hould an )RD !e
normalizednormalized forfor $elational $elational data!ase design purposes>data!ase design purposes>
8/19/2019 Normalization 450
44/44
D#*/$**#&ND#*/$**#&N
• Nonnormalized )RD Nonnormalized )RD " $seroriented$seroriented
" Mood for capturing