Professional Documents
Culture Documents
-.
CH!t-t'/t:t~"t - ~ - - - - - -
"
r... ObJectives ·of Normaliz.,a.. ., ion
.~·
1· :
....
' . ( The basic objective of logical modeling
. . .
is to develop a 11good 11 description ·of the.
-·~ ..
it.'i relationships, and lts constraints. For da~a, ·
the ·relational model 1 this means that we mu· 7
i~<mtify a suitable set of rela tio~ ) How st
ever, ·the task of choosing the relations
d1(6cult one, because th.ere are many opti ' is~·
ons for the designe~ to consider. This
is _devo ted to explaining some met chapter
hods of improving logk'al design.
presented here are based on a large· body The tech niqu ~
of research Into the logic.al design pro
~~ncrally called norm alization. ·
c~
~ 1Ee_p~~~7:cj.:-nq~al_h:~tlon_!s ~2 produ.sf! -~--~ !'le . · 1 ·
_rriodel.Qlthe...or,~.lfili.Qru 9(.tl)e sec_ t:f_~;.~~~o~~.!Ll~.a.Jair:h~I
~Q~Cn?r_is_e.(By.fpllp_wJng.ilie pnn cipl ~_.o
~~-=~ a~~~c a d~~E-~1ia~}s h~ghly fl1:~i~l:s.! f x:io_i:t?a!ii.,ati_on, ·
m:e dcd to acco unt for new attributes, ~!~~-~[}g the_ model,.t~ b~.~t1:,nded wfi.cn,
enti ty sets, and relationships,_ We can
[eclundancy in the database and t.nsUrc tlm also reduce' ·
the design is.free of cert ain upd ate, inse
and dele tion ano mal i~. An ano ~ly rtion,
state is -~ incoruistent,
of the diltab~c. 'ff'iliese anomalieswerc incompl~c;,· or conc raclicto ~-
someinformatioii:wemight l~se inf~;ma ce
··presefii:',wewouli:l un'a blet o reprc .sen .,
tion wh~~-i~--tipdac;w
wl!-;;;~ld. r·u-;;·th~ ;isGf having data-b;come'fnconi'i"stcnto_yer. ;;~ p~rfoi,;:ed, and.
. Research"i"nto iheseanomalies·was·first ~im ~t' --. -·· •~ ·
defined the first three "normal forms".
ao·n ;by Codd, who Identified the causes ~q•
~~ is in IL_specific_,;ionn
satisfies the ~ t ~.f. Jcq uir~ ~~i (1µ
_f9 uh~ t...f m:m .• Not e that the cons
al.fo_ ·· :~t
Wl!-di_scussarc schema corucraints, pen nan train ~
cnt properties of the relation, not mere
some instance of the. relation. Late lf,C!~
r r~ea rch by B0yce and Cod d led
of the third of thes_e forms . Add itional co a telinemet}t
research by Fagin/and indepcndendy by
;• resulted in the definition of three new Zani.olo
normal forms.l_AU of the normal forms•are
ncsred, ig_th~L OO ..l@ @e.s the cons
traints of the previous <?_!}~~-tj~ a__'~
bec aus e eac.h_c_li.ti:1i~1a.tc.dla·tx.d oun b"etter1 fo · •
d in the. previous form. Flgure 7.1 show
sev en normal forms arc related. Toe· s-how·,th"e
largest clrd~ represcnt5 all relatloru. Am
set of all relations those that are in fuse ong the
normal form arc represented by the next
circle. Of those in first normal form, -largest
ther e are some that qualify as seco
form as well; these fall into the nex
t circle, and so on. O~r .d'5 ign obje
nd nonri~I
be to put the schema in the hi~hest norm ctiv e sho~ld
al form that is prac tica l and app ropr iate
the app lica tion . ~o ~a l~t_(o~'. -~~ £~: ·
Jl~i ~g. !_~ :?~~ -~n }_? . a_!:i_~~e~ n~tm
Alth oug h there is still a·~rcat deal of rese
arch being don e on i:hls process, the al ~ ·:~
form, domain-key normal form, is the "fina last no · ~
l" one in a· sense which we will discuss later
Normalization requires that we have a .. _
clear grasp of the semantics of the applicati
on.
Merely examining an instance extensio
not provide enough infonnation
or n. is nor sufficlmt, because an instance
docs ,;. _
about all the possible values or combina
for relation attributes. tions of va~ues .
· "· ( ln :ittcmpting to pinpoint the caus ·
es of update, insertion, and delcclon anom .,-~ .
rc:-c.1.rchccs have identified three importa all~,~'
nt kinds of dependencies: f~~2!1.alA.~
.. den~iis multivalued dependencies and en~- ·,
r-· app'.ear'"fu th; res;"ich join dependenc.iesJ Additional depc
7,ceratuie:--- -- -- -- -- -- '-- ndeni:lcs ·
~- _. ~·-'
·.:•
' •!
7.Z Functional Dependency 223 .. ~
•:,.:,
rif~'. '.,
1Jii1•:,
~t~·1;j:
,\,
Hl•1:1
_;;.:,. ; ,
_:.';Tr (.
:};)'
',:/: ·,
!i_fnl
;rr,.,
: •~ ' • : , t
':!'),I '
,.;
)il..1:-11
' •
¥,~A.-'
i;(;;.ir,
·(; rJt..:,w·
4 ,
;.i} . .
:~
. f,f .
,,:J, •
•,,4,j.A
.; .
.
/J4;'"1
I••
·
))Jr; ;
.:~··w Figure 7.1 ·
~ON: (If A and S are attributes or sets of attributes o~ relation R, we sny that B is fu.nctionaliy
;. dependent on A if.each· value of A Ln R. has associated with it exactly one ..vnlue of B ... •·
:· inR.> ' . . -~ -7 b . . . .
f{ !"-:. '~ t •· .., •. "
ns,. :!fc write this a/ ~ ~ B, ',i:cad ~ ~ A.~io~lly deter:m.in_ e,s ..B"~ ~r ~ ?=~~1:1:1!~
7~ a;~: )
(Note: If we wane to be very explicit ~bout which relation we are discussing, po.ttlcularly
in the case where A or B appears in another relation, we write the qualified name~, ns
'·. .• in R.A -t R.B.'( This does not mean that A causes B or that the value of B can be it .
:\ calculated from'the value of A by a formula, although sometimes that is the cose. It
•,. · simply means that if we know the value of A and we examine the table of relation R,
.~.. we will fin~.rily_one xn,lue. of_f3 inall the rows that have the given value of A at .iny
'· on~ time. Thus when two rows have the same A value, they trtust also have the same: · ·
}.~... B value. However, for a glven 8 value, there may be several different A values. -Whet),
1~\,.·-··.
~~(~• · ·
a, ~c~~~a1~ ~ ~~exist:s, the attribu~~ ~f.a!_t:r~~t~ .':? ~e l:f.:.!!.?~.,~-f t~., .~
_,:_rro~ IS ca11:ca a ceterm:ihm i:r::--- , · ·
~!t .· •:.
. .._:. .. ~
, !;
!;•:
, .
•'..>
'• ,
•.'
,.
•~
:. J'
·l
~LL4 -~-fo rmal izati
~on 7""' ~ - - - - - : :
- : - -
-- ;.·•,. ' ·~l
~
ider the following relation:
• To i?luscrare funcc ional dependency, let u.s cons
\'
STODENT csro10 , sTONAMt, MAJO
R, cru:o ITS, STATtJS ,
5 0C'::~0L /
- • - - __,,,_ --
- -
->._ .. - -·-- -
; ..,._.,. ••• , - - . ·
soe::"\_j
~- _: _:.~~:__.;:~::.:::~~ ..;;~,--
·, __
· ·· '
the righ t is func tio 11 d
to indi cate that each of the attributes on na Y cpcn dcnt on STIJ ..
\=~o- , we have , ·
Similarly
~~I~-~~~; = ~,;_,,J
t on CREDITS F ·i~
Also note chat STATUS is functionally dependen
TUS is autornatica~t =p ie. ~ di_
va!uc of CREDITS is known to be 15, the STA
~I~:;T:u~_j
wnre ·- Y
· hman..,:.,Wi
. .
since two freshmen may h : ,·~,.
However, we caM ot write STATUS -+ ~I TS , S1060. Fo ~:~ Jif ~
ferenc numberof credits. as we see in the records of S1006 and
S does not functionally dcte · . -,-.,
functional dependency1 the dete rmin ant CREDIT
the other atcributes o~ the relation. Note also
that the V3lue of CREDITS is no~~~
its, uniq ucn ~ .
same number of cred 50
sarily unique. Several scudenrs could have the
. The inscanc.e ln Figure 7.2 did not r~l
not a necessary characteristic of determinants
..
•• '
------------------ ----------------------------------
\11tl' , FJgure 7.2 STUDENT Table (Each student has al most one major)
demonstrate the lack of uniqueness of CREDITS, which shows that we must be c~n:ful
in making jud&ments from instances only. ·we need to concentrate on the meaning:. of
the attributes and their constra ints in identifying functional dependencies.
; .
)
,.
,.: \_,/'"
J
· values can be used to d isti.T'1guish one row from another. Since -a superkey idi:ntilies
.. ~ch entity uniquely_ it-~tlonally d~t~;;,l~es-·an °th'e~ttrlhutes of a rclacion.~f:QL
.,!~c. ~ D~J-~-~JD_qgure 7.2.,~1},JJ.!2..iu..!i~P.,er~~Y.:.. So is the cornbinatlo_n of
{STUID,STUNAME}. In fact, {STUID,any ocher attribute} is a superkey for •this
relation. The same L,; r:rue for {SOCSECNO,any other attribute}. · ·
b.~<:a~djdate ke!._!s ~~-petey.:..5;1gi_~r..no.proper...subset _of ~ts_a_ttr_ipu~es_is. i~cl( n'.,__,
supe_r~ey. Jnerefore, a ca.."1di ate key must be a minimal identifier. In our example, the
superkey {S1UID,STIJNAME} . is not a candidate key because it contains a proper
1- subset, STIJID, that is· a superkey. However, §..TIJID by itself is a cnndid:ite k(:y. ·,
I ~milarly, SOCSECN'.) Is a candidate key. !f.E.o two stua~:,!~~e_.Penni,t.tec(to hn.;; the_.:.·
~f!l~l1Jbinacion of ~ame and ma;or v~es, ~e _:o~bi!:1~~01;_{~~~E,MAJOit} ~
~ -19;.a.~ _ke a ,ca~d.~.t~J{~y.:..A relatton maynnve several cnnctidate keys:· We,vill"
use the term •~2!!1P9!}.t~.. kei'.. to J~e.r.,.;o a_,ke_y ~~~F. ~e95is_ts.of_mor~.•t\1a,n_one_nttribute.
We will also drop the set brackers In showing secs of attributes. · .
~.P.r:i~aty...kruu....can9_idatLk~y_that,is. used ..to)de;:ttlfy tuples in a relation.) In
,:n, . . our example, STI.JlD might be the primary key and SOCSl:CNO-~i'naltemacikcY.· ,
.. ,. These two attrilrureshintcionaTlyaecerm1iif' each" oi:ner7""ano-a1Cof ch;· attrib-~te; nr~--·
:,;j,. . _ . functionally dependent~ each of them( ~tho.ugh not explicitly st1;m:d ln the definition,
~~; , ~ - an important charactt-ristic of a primary ~Y,.!!. ~none of its_a,~~tcs may_hnv~!!_
/ ,. · u - (l ~cs) If we permitted null values in keys, we would be unable to tellrccords a~~rt,
•,} · 1/ since rwo records with nu11 values In the: same key ~eld mlghc be lndistlnguish.:i~le.: le
r, · is aJso desirable to enforce die·11 00 nulls" rule for··candidnte keys. •··
J·t.~·
, , . ·,"'t
., •:. .:;~;·
)'
set of attributes, A, in Fi. We cait this set of attributes the closure of A or A+)Cleoriy, ·
if A+ is all of R, then A is-a superk~y for R. We could-find A+bycomputing· all of F+
and then choosing only those functional dependencies where A ts the decemrimmt, hue
there is a shortcut. The following algorithm can be used to find A+, given a set F of
functional dependencies: ·
2:• ault : • A:
•hila (result changes) do
for ee.ch functional dependency 8 --+ C in F
if B is contained in result then result :a ro11ultl.J C:
end;
A+ :.. reaul.t;
yz-x
WZ-+ y
Let us compute wz+: We assign WZ to the result and enter the while for the fir~t
time. We look for an FD whose determinant is contained in result, which has only WZ
at the momenc. The FD wz.
--+ Y satisfies this requirement, so weassign WZ U Y to
result. Since we had a change in result, we enter the while again. Now we look for
an FD where W, Z, Y. or any combination of these three L'i a determinant. \YJc c:m
use 'rZ - t X , and now we assign l-'\rZY U X to result. Since we have found that every
attribute of R is in 1,1,Z+, WZ is a superkcy.
To find W+, we assign W to result and enter the while for the first time. Using tbe
FD W ,-+ Z, we assign VI U Z to result Since we had a change to result, we enrer the
while again. This time we use WZ-+ Y and we a5Sign W.ZU Y co result. Now we look
for an FD where any combinat ion of WZV appears as the determinant. This time we
can w e yz -+ X, and we assign- wzy U X to result. Since we have found that every
atttihutc of R is in W+, W is a superkey for this relation. Because it has no proper
subset that is also a superkey, W is a candidate key n.s well. Note that we now know
that WZ is not a candidate key.
It is easy to verify duit yz is not a· superlcey. We start with resuit := YZ'. Using
yz -+ X , result becomes VZX. · Now we look for an FD where some· combln.>.tion of
Y2X is the determinant. Since there is none, we cannot add any new attributes to
result. This means that :a+
is only 'YZX, so W is not functionally dependent on YZ,
which means that Y2' is not a superkey: . _; .
Given a sec of functional dependencies, we wouli;l like to be able to dctcrmi~c whether
any of them is redundant, meaning that it can l:ie derived from the others.: To do ' so,
we can use the following algorithm:
l • . Choose a candidate FD, say X-+ Y, and remove i~ from the set of ~Ds.
2. J:'HW.t :• X; , ·.•.::,i;-J,.
while (resul.t c:hange:s and Y i5 not conta.1.ned in reaul.t) do
for each FD, A·~ B, remaining in the reduced ~et of FDs,
226 Normalization -7
HI ·-Inference Rules ·.
erence axiom s or A ~ ot g:
of inforcnce for function al depe nd encies,, ca~lt!d infthe FlJs logicallylmj;Ifcd y : ·.'·
Rules d all
er, can be used .ro fin
~axioms;-afcc~·che·i; d~esvelop
are soun d, -m ~ n ln g _ ~ ~ ~ at !_ .~ l) S ~ ti
en ce :
cy tli:a'i;
·set of FDs. These rul de ncy an d th at any functional deEf!nden
en
of the definition? functi secon=o;-~i~g· chem-is-·crue.-They""ie -also
on:i{ de.p 'completi;~
c;n"7be-dfrived· froma giv
en inf erence abour dependencie
s, so that~;
e ev ery .valid
meaning they ~canbe-usedbe''toderived from a given set of FDs, the given set of FDs does· · ;~
deriv
if a particular FD cannot FD. ·
not imply that particular ing axioms·~
s of a relation R: Th e follow ·1
Let .A, 8, C, and D be
A and
subsets
C.}
of attribute
.,
. hold: (Note: AC means ·l
1
,,,,. Fl. Reflexivity -+ A always holds. Fu nc
tio na l]
"-r'..
9
ff A - B an d 8- ,. C,
Th e following rul es
Union ·
the n A _. c.
... -
we will concentrate ins
tead on the ir pra ctica l ap
R th . f ;'I~$
I
nd en cie s. for a rel ation all fun t'
is a set of foncri onal ,depe ·• e set O
c ioµa'.~.
.., (I f F ..
. . th b den·ved c.,rom F, F+, --is called the closure of F.) A~t ro ng '!,
.. .e if we were to a ;!,
dcpend~ncies , at can
axioms are su tnc icn t co
find
comp
all
ute all of F+: thar is,
the fun ~d on al de pendencies ·in F+. H!~ :
er, . e
rules
-~
I
repeatedly, we would lex an d cak e a lot of time.
I
1 would obviously be very co
mp eren e;·~
,;
nd enc:ics F of a relati
on R, we are often inc
t
~-,
'v
are fun ction ally de
in R th at
finding- all the amibures . ~- .t
~~:____.:..-- --~~ - '.t
27:8 . Normalization 7
1£ A i s a subs et of result,
then result :• ruult ua ,· ·\.
-,.._~
·1
t ond hen the FD X -+ Y i::1 redundant 1_ ·
'\
y from the se, since it ~ be derived &om the ~
We could then remove the FD ~ -,h d mo;ing any that can be derived from !
B . every FD m t e set an re ~
ather FDs. Y rescmg f FD5 u·valent
1 co the original 5ct ·· ·l
the ochers, we can find a nonredundant set O eq f FD 11
r II · sec o
fo r c~ample, ?iuppose that we have the 10 owmg
s·· · . ··1
(1) W-+Z
(2) w- Y \
\
(3) Yl-+ X
\ ·,.
(4) wz- Y \
\
We be~in by testing (1) , W \Y/c assign W ro result. Now we search for an FI?
- •z.
[other than (l)J in which W is the detenninanc.. We find one in (Z), W ~ Y. ~o':J':e
assign WU Y co resuit. Searching for an FD having a determinant rhat 15 contame d.
WY , we find none. Therefore, we are unable to show _that ·Z is contained in result, ~ -- ;
we conclude that (1) is not redundant. ·
Next we test (2), W _. Y. We assign W to result. Searching fur an FD or.her than
(2) whose determinant is W~ we find one ln {1), s(i we ,;:an a:;sign t'VZ to result. Now
we seek an FD whose decermioa'n t is contllined in WZ. >Ile find {4) , WZ '4, Y , and
now we can assign w.zy to result. Since Y Is now comi.tn(!d in T~ult, we can exit the'
while and conducle that (2) is redundant. We now eliminate (2) from the set o f FDs;.'
Testing (3) , we assign 'IZ to resul t. We look for'an FD orher than {3) or (2) whose;
dercrininant is contained in VZ. Finding none, we conclude that {3) is not redundant. ,
Testing (4 ), we assign WZ ·to result. In (1), we see that the determinant, .W, is .
contained in result, so we could add the right side of (1), Z, to result, but it is already ·
there. There is no other FD whose determinant is contained in \>\-Z, except for (2),
which we have eliminated. Therefore, we conclude that (4) is not redundant in th~~
reduced set of FDs since we are unable to get Y in result. . •.-~
Somecimes we would like to be able to substitute one set ofFDs for another. If F ~
G are- cwo sets of fr>:,
then F is a c~ver or G if every FD in G·is also in F+, which
means chat every FD in G can be derived from the FDs in F. In the special case h ·· ·
Fis a cover for G and G is also a cover for F (i.e., F+ .. G+), then F and G arw • .d
to be equivalent.: A cover, F, for .G, is said [? be nonredundant if F is a cover ; 0 ;~h ·
but no proper subset of F is a.fover for G. . t:
G mny have several nonredundanc covers, so we would like to be able to ·find ·
. a st.andard , or canonical fonn .one1.1-Uat
. Ill
f FDs .in .1t and l5
.~1.f.
L -
hns che fewest num1Jt:r o 'ch ,,
each FD has a single attn'b uce on th e ng ·· ht s1'de. . ' m Wn1-~_14. ,
A ser of FDs, F, is said to be minimal if ._1ih1
~;Jf .
( l ) F has no redundant FDs ~~,
-•~:
(2) The richc side of every FD in F has a slngle attribute :(i
{3) No attribute on th e left sid•t of any FD in F is redundant. ·:~
~1{'.
II_
.
.
.
I I
I ,
7.5 First Normnl Fci~ . 2°29
I
t
(\Y/e w;ll use a counrerexa~ple co ~escribe
first normal fonn. If we ·assume that :i s'.rudcn
iple mRjo rs in the
r, and we try to store mult
is permitted to have more than one majo
STU DEN T table might appear as in Figure 7.J(a).
same field of the student record, our
normal form, which is: )
This example viola.res· the definition of first
,)
' .
.
. ,v .
.
.
or each "cell" of the table, contains only
This means that each attribute in each row,
0, who
ifiin i'
. . ,. .,(•, •• \ ..~ : .I
I
• <. :' ; .
2.30 Nonnalization 7..., ,
cR£ OI'l 'S ISTA TUS I SOCSEC
STUNAME 1 •
1u11JOR NO 1
I , ..,,.
--- --- - 1-- --- -1- --- --- -1
1STU ID , --- t-- --- --1 · ., 9 soc I
1-- --- ! --- --- --- H' tor y 190 I sen J 100 4 ...
~ t1. Tom I .1.s
S
1s10011 mM ''' ___ 1 -------1------- 1-- --- -1- --- --- --1
,-----i--------- h 195 1sen 10101245671
1s1003tJones,MarY -'~~=---- 1--
1-- ---1 .~- "--- ---- -- I
1s1 006 !Le e,P ame la
,~s -----1tFr---esh---1--------- 1
tCS C - I
108 8S2 087 61
1. · I I
I I Math '-- --- --1 --- --- 1- --- --- - I
1·--- --1 --- --- --- --- 1-- --- -- l
c.3 jJu n 10993209851
1s10101surns,Edwardt.A.rt . 1
I I · l I
1English l _______ ______ ______ _ I
___
1-- --- 1-- --- --- --- -i- --- --l r 1 1 1
IS10601Jones,Mary ICSC fre s h f064 6247381
l ~S I
Figure 7.J(a) STU DEN T Table
major)
(;:~:t~t---
s may---have---mor---e --- --------
than onr
..... ~
----... _}i
I
ICOURSEflSTUIDIGAAD~I ISTUIOISTUNAME I
1------1-----1-----1 1-----1-------------1
ISlOOlfSmith,Tom IV
IART103AIS10011A 1-·
1-------1-----1-----1 1-----1-------------1
JSlOlD(Burns,Edward I
' !ART103A}S1010 I · I
1-------1 - ----1----- 1 1-----1-------------1
I 51006 l Lee , Pamela I .,,,-
IART10 3A l Sl 006 1B I :/ ·
1------ -1---- - 1-----j 1-----1-------------1
1S10031Jones,Mary
(CSC20l AI S l.0 03 1J.. i ~N'
1---- - - 1------1-- --1 ---------------------
.STL)', Table
JCSC2 01A I S1006 IC t~'
l------- 1--- - - 1- - --l
IHST205A1Sl 0011 I tCOURSEf!FACIOISCHED )ROOM I
--------------------- 1-------1---~-1-------1-----1
i~RT103AIF101 !MWF9 IH221 Iv ✓
CI.i\SS2 Table 1-------1-----1-------1-----1
- • ! CSC201A]Fl05 !TUTHFl0IMll0 Iv'
r-------1- ·---1-------1 ·----1
'. HST2D5AIF202 . lMWFll !H221 I
~COURSE
--------------------------
Table
Flgure 7.4(b) CLASS2, STU, and CO~SE Tabler. ..
Agure 7.4
Since there is.no other candidate key, COURSE#,STIJlD is the (composicc) key for
the· relation. Ignoring ttlvlal functional dependencies, we also have the functio~ol
dependencies · ·
COOltS!,lf-+ FACID,SCH!!D,JtOOK ,
STUID - t 5Tt7l0\MZ
.~. on the eoa,. '
·1 .
7· . " that arc functionally dependent
232 :,. N~J~;,;Cion • . set of that com.
we fmd atm buce cc1.on.a II y deN 'ndent on 11a sub
d d
/ · [ 1 e cases . L I fun r-- ·
y epen enc on the
n both oCOnes • ~ so oc fully fun ctio na
. . URSE;;1,STlJlD.h uut:
~ mac~on that suc attriburcs are n
bin:u:1on. We.. say
.
com bin ati on .') ·
. . )
•✓,Definition ~f Full Functio1~1-T.l De· pend• en ce
na11 d pendent on an atmbute or set
:J
.
DEFlNITION: (1n
1
a.relation A,'attribuce 8 of ~ na
'of .mributes A of R if 8 is.. functto
i5 flf llJ fu n:~ t
Y epen
o: ·1
A ~uc no t functionally dependent ~
1
.J
-
;,,_\~•"\.
on any proper subset o( A,)
.. COURSE#,STIJ!D•~
fi .. . ally dependent on atio
. •
AME 1
' unctto~t: of char com
bin n, STUID. SJ.m· j
In our example, although STUN ent on the proper subset ;j
ic is also functionally depend enr on a proper .su. II y denr Pnd bin!)tjon ~
ED d RO OM are (uncttona ly de pe nd en t~.th. e co m .~ ~
SCH , an fu!{ fun' . nal . ·-1
ilarly, FACIO,
COURSE#. We not e
,_
that GR AD E is Y cno -
. J
CQ UR S~ UI D: M
~~,
Il
re mfo rma
en we delete the teGpttl or'rh .
occ urs ,£ we try to ms 1.
similar problem ly occ urs wh
A del etio n ano ma
registered for any course. 7;•: .
l.
I ,i • 7.7 Second Normnl Form. 233
•
, n:Wation that is not 2NF can be transformed ·in~o an equivalent sr:c of 2NF
re Iat1oru. e perform 0 • t' th ·· 1 I · •
possible to - • pr !~c •~ns ~n e .on~~~~ ,:C :i~•~t:. •~~uc}:l_ o. w_ay t~:it iLis_
tflrs•-· gee back tfiU2J:ig~l}__~l by t.11.fu.!:ig tne J~!\_Ql.the_projections, Projections of
Esse:r
fa
are called lossles~ proj ections ~nd :i.~c dlsc:ussed In more derall In S::t~ ?_:14.
al~y, t~ make a relation 2NF, you 1denu(y each nonfull functional dcpcndcrv.:y nnd
~ pro_1cct1ons by removing the attributes that depend on each of the dctcnninants
so identified. These determin ants are placed in separate Tclations along with thei r
dependent attributes. The. original relation sci!! contains the composite key and .1nv
attributes that are fully functi onally dependent on it. Even If there are no attribut~
fully functionally dependent on the key of the original relation, it is lmpominr to keep
the relation (wlth only the key attributes) in order to be able to reconstruct the original
relation by a join. This 11conn~cting relation" .shows how the projections are related. ·
Applying this method to our example
__we first identify all the functio nal dependencies char we are concerned abour. They arc
\
~=··---\
, ~::io::~
COORS£ (cocm.sef, FAcrD, s c m:o, ROOM)
I STO (STO!O, STUHAHE} "'
'----··· ·- · . --·· ----
The resulting relations arc sh own in Figure 7.4(6). Note that we could r~construct
the original relation by talcinr the natural join of these three relations. Even if there · ·
were no GR.b.J)E attribute, we would need . the relation CLASS2CCOURS'E#.STU1D) -~ ·
in order ro 'mow which students ar~ enrolled ln which cours~. Without It, we could .
not join COURSE and STI.J. Using these new relations, w~ have eliminated the update, ·.
insertion, and deletion anomalies di.scussed earlier. We can change the coum schedule
for'ART103A by updating the SCHED column ln a single record _in COURS~. We
can add new cowse infcmnation to COURSE without having any student reg15rered
in the course and we can insert new student information by adding a record to fi'TU,
without hav~g to insert course information for that student Slmila~ly, we c:mdrop a_
'registratlon record from CL.ASS2 ·and still retain the informntlon a~ut the c!'.Tsc:t
C'QURSE and about the srodent in STU. · .:t;.
~i.·.
,, ~
f'
. •:t:
·:•,t·
'll.
'I
..\1. . .2.34 No~lir.atiQP 7 d
.m. , ml Transitive nepen ency
JiI . la ,ons are L. •r than those in ·nth
m flnonnal
':'~ Alch ough ..,.cond..normal;form re nd- I . Ot;tt... II . fonn,
. rl...:..".
..~,
I ,· "" . . d e ec1on anomalies. Consider e o owmg rtlatiOll}~
•[~ may still hove update, insertion, an . . . };
,'
i/;1 . • MAJOR CP.EDI'l'S, sTAl'OS} )1
1~ STOt>ENT (STOID, SftJlW!l'! • ' · ·.:~
;;j/ · _ . . H . the only candidate key is STIJID;:
)i Figure 7.5 (a) shows an inst~ce of th is relat1~lcr ::;ibutc of the relation is functioN!-llY1
',fJ
j(
so we will use that as the pnmary b\ E~e
dependent on the key, so we have t e O1owin
7.
g functional dependency. among ochers:.i
~~
,F .
,...
''
El •l~~i
~·
STUID - t CREDITS . . ~~
j
,ff.: ,
)~{' However, since che number of cred1!.S detemuncs ..:iC"T"A'TIJS
. as discussed in Section 7.2,:~
. .
-~1
;t'• Ul. 1
?J
.ill!
.'·;~-
wec::I:v~ s,Ams
.
· . ·:j
d::~
; if/, Thus STIJID functionally detennin cs STATUS in two wny.s-direcdy, and trnn.sitiv. -1j
_~
1
)J through STATU.S:_. _ -· --- ·· ·- . . ___ __ _ ..
~~,;. .(_t-1·
f/
i ~t F,,;;;D : .""".~,...,. ~ (~.:~· :-.~~~~>
.~ ( ~D .:::!.~".'."!l \ :?-'ii
:Jj R;c;i, ~ t transitivity is the thi«I of Armstrong ', axioms. Thus a transitive depend ~
. /r1j is orie that "carries ovei:" another attribute. EYu¼.tpJy,_L~J.9v~_~eQ!;nd c q ~ ~
; .~-4 when one nonkey attributt; dete~e.s another, no~~- ~':!!!~.!!te. For thud normal fo~
{ijf
:.tf i~
p
weconcences.'
rareoo·reracions
dependenci
w~th only one candidate key, and we eliminate transitive 1
· 1
. !,~J).
4"~~-:
1Lf
{;a: ·
!:~~- ·
l.~'. -£
j{(·
; SJ. Third-Normal Form
~11: \
i1:[ Transitive deJ>endencie.s cause insertion, deletion, and update &no~ics Fo
..
ij J
th t
l!l
:.t
1-L
in the STIJDENT cable in Figure 7.5, we cannot insert the infortn.ation,
with 30 creditS has ~oph Status until we hav: such:a sru~ent, bccaUSc
insetting a record without a S1UID, which IS not perm1tftd. If we delete th
that~:~. .
r
~
' .; the only student with a certain number of credits, we lo.;e the infionnac· eabo. "':
: I If ha
~ we ve several records with thc·same
__ .J, 10n Ut
status associated with those cn:u1ts. · .i
_value and we change the status ~iated wl?1
that value (e.g., making 24 credir.s· ·
have scacus of Soph), we may acetdentally fail to update all or the records. leavh{. ·
database ~an inconsistent state. Because of ~ese ~h!c:ms, it is desirable to ~
- - · -···· ~
5
7.9 Thlrd Normal Form 23.
. ICR£DITSISTATUSI
IMAJOR
ISTUI01STUNAME l I
1-----llS -------11H
1-----To -------yl91- - tse n t
istor 0
ISlOO mith, m ---- --1I
--- ---i!Se
1-----1-------Ha--ry---1!M---ath----1195 n
. IS 10 03 1J on es, --h-- 1I
--es
1- --1-
--06 -- -- --me--la---1ICS ---- -~-1ll5-------1'! Fr
C
IS10 1Lee,Pa
I .:
---10-,1B
1-10 ----
. .--s,E
--urn --ard1-1Art----1-163------1-!Ju--n---rI
--
1;·1,t
' JS dw
~---- -1---ne--- ------ 1---- ---1-I 25------1-!Fr---es--1
h I
ICSC
IS1060('Jo s,Mar:}t
~-EN
----7,5--(a)-~Sr--uD
--ure ---- -- --
le
-- ------------------
Fig T Tab
rm (3NF)
De finition of Thir~ _Nonna.l ·Fo
'
normal form by saying tha
and nothing .but the key.)
· . ·
fotn},~~_l_~~- ro..:,ec_!~ ·
j / n ch~~ _a s~o ~n orm al- f<?~,:elation.for,third_t,1f)tm.aj_key
ctfonally dependent on ano
ther non atttibute. If such a
nonlcev attrioute 'ts funstS, we rcritovcthe functionally dq,encfent attrlb~~-from ~
eperulency CXt
the~ .
rem n~~
ctio
.tncwrclatio~with itsd~tetm
l.nint "Q_le-dei:ennlriant Bin
entl~~cy is
relation. liclnfi'flioii"n. ' For'--o·Jr STU example'; sincti:he und"eslrnb'fe'ifep !;
-m np lr el at set of relations ': ··'·
CREDlfS -.. STATUS:-we fonn the
,,.,.
..i:1
236 · Normali2atiol}.] _!._{'
/ MAJOR, CJU".0:rTS)
sT02 (STOIP, sTIJNAME, • . ·.:_ ••.
0 ITS STATOS)•
, <cnt
sir11--rs ' ( f e may de"cide not to stott
. ?.5(b). ln actt w . · "
"(on
1 is shown in Figure tli c-rATlJS for those VlCWS that need
This decomposi [l d calculate e- ..> i, • .1 t
Us · h database at a , an 1- • • ~ i
STAT 1n t: e
ic. In that case, we simply drop . t~
th STATS reIBt1on1 · -A b Cod~ lt.is
·s the origtnai one dcvclol:-"""' y d fi i lri
This definition of third norma .orm. i didate key, bu·c was found co be c c t.
sufficient for relations chat have a sdinte c~n and ;here candidate keys are comd
cases where there arc multiple can i at~ de~•t'on of third normal form, nnmc 0 \?
r.lr
11
and overlapping. Therefore, an improv\ ed ake care of all cases:\ .'' •. .
developers, Boyce and Codd) was formuiatc to t . 'l ".! ., ··
. JU\NJt;
t,,\O:(AME,.~ F!,_l~. -i- DEPT, DA'J.'ERIJU:D
'
' •
•• FACl (DEPT, OFFICE)
FJ\C2 (FACNAME I OFFict:,, RANX , OATERIFEO}
I
C.. The key of the fim rdntion is OFFICE, since a deparnnent may have several offices, but i
each officeb~l~ gs to only one deprirtment. le ls clearly BCNF, since rhe Q!l.lY_ de term i-
nant is the_k;ey. The key of the second is FACNAME,OFFlCE. It is aiso BCNF, since
i.sthe·lcey~·Note;-h-owever; mai: our fmnlsclieme does not show the
its only determinan t
functional dependency FACNAME;DEPT ...... OFFICE, RANK,. DATE;rilRED. (Nore: .
. If we had chosen FACNAME,OFFICE as the primary key of thc-otigina l FACULTY
relation, we would have OFFICE - DEPT. Sine~ OFFICE is not a candidnte key, the
relation would not be BCNF.' ln fact, it would not be 2NF, since DEPT would not he
l fully functionally dependent on the key, FACNAME ,OFFICE.) )
A relatioi-1 may have overi.app;ng candidate keys and still rbe-B.:tC;,w;N~F-.F....or cxamplei let
I
l
us consider the relation ,
Here, we will assume th~t a student can have only one major and that borh of the
combinatio ns STIJNAME,STUADD and·STUN ~E,MAJO R a·re unique, so we hnvc
two overlapping candidate keys. If we choose STUNAME,S11JADD as the primacy
n
key, our on ly other dcrenninam, STUNAME ,MAJOR, is c:mdidnce key. Therefore,
the relation snJ is already BCNF, and there is no need to decompose it. .
Any relaciqn.•chat ls not BCNF can be decomposed into BCNF relations by. the
method illustrated. However, le may not alway5 be desirable to
traruform the relation
into BCNF. In particular, if there is functional dependency that ts not preserved when ·
l
;
l
we perfonn the dccomposltion (i.e., the determinant and 'the attrlbutcs it detrnnines
end up In different relations), it is dif6cuk to enforce the functional dependency In the
database and an importanr constraint is lost. In .that case, it is preferable to settle for
JNF, which always allows us to preserve dependencies. Our FACULTY rclat-ion provided
an example in which we lost a functional dependency by normali.ting to BCNF. lri. the
resulting relations, the attributes FACNAME and DEPT appeared in different relations,
and we had no way co express the fact that they determined all ocher ntttibutes. · ;:
•,
.
,1:
-~
To summarize the various normal {orms defined by functional dependencies.let us con~i
side~ the 'followirig relation that store, infonnation about proj~crs in a large business:~
:;~;:;;:-:;;;~~--:;~;~-: ;~---:;;;;::-;;;;;~;:;;~;;;---:430001
[55000 (
:I ~J
------1-------1I ------1l
'~
Levine 110 9
-- -- t ----·-- 1------1
I
Jones-: 12 _____ : ______ :
7f."
r Levine I lO • 18
------ 1-------1------J
Levine:10_. ___ ; ______ :
I
l Jones 112
. ------1-------1------1
.: Jones I 15 ·
----------------------
I
I ·
(
1
• ~,h project hns a unique narne, hue names of employees and manngcrs are.. it
00~~ '
z. Ench project has one manager, whose name is stored in PROJMGR. ·