Database
Database
DatabaseSystemConcepts,5thEd.
Silberschatz,KorthandSudarshan Seewww.dbbook.comforconditionsonreuse
Chapter7:RelationalDatabaseDesign
s FeaturesofGoodRelationalDesign s AtomicDomainsandFirstNormalForm s DecompositionUsingFunctionalDependencies s FunctionalDependencyTheory s AlgorithmsforFunctionalDependencies s DecompositionUsingMultivaluedDependencies s MoreNormalForm s DatabaseDesignProcess s ModelingTemporalData
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
TheBankingSchema
s s s s s s s s s s s s s s s
branch=(branch_name,branch_city,assets) customer=(customer_id,customer_name,customer_street,customer_city) loan=(loan_number,amount) account=(account_number,balance) employee=(employee_id.employee_name,telephone_number,start_date) dependent_name=(employee_id,dname) account_branch=(account_number,branch_name) loan_branch=(loan_number,branch_name) borrower=(customer_id,loan_number) depositor=(customer_id,account_number) cust_banker=(customer_id,employee_id,type) works_for=(worker_employee_id,manager_employee_id) payment=(loan_number,payment_number,payment_date,payment_amount) savings_account=(account_number,interest_rate) checking_account=(account_number,overdraft_amount)
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
CombineSchemas?
s Supposewecombineborrowerandloantoget
bor_loan=(customer_id,loan_number,amount)
s Resultispossiblerepetitionofinformation(L100inexamplebelow)
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ACombinedSchemaWithoutRepetition
s Considercombiningloan_branchandloan
loan_amt_br=(loan_number,amount,branch_name)
s Norepetition(assuggestedbyexamplebelow)
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
WhatAboutSmallerSchemas?
s s s
Supposewehadstartedwithbor_loan.Howwouldweknowtosplitup (decompose)itintoborrowerandloan? Writearuleiftherewereaschema(loan_number,amount),thenloan_number wouldbeacandidatekey Denoteasafunctionaldependency: loan_numberamount Inbor_loan,becauseloan_numberisnotacandidatekey,theamountofaloan mayhavetoberepeated.Thisindicatestheneedtodecomposebor_loan. Notalldecompositionsaregood.Supposewedecomposeemployeeinto employee1=(employee_id,employee_name) employee2=(employee_name,telephone_number,start_date)
s s
Thenextslideshowshowweloseinformationwecannotreconstructthe originalemployeerelationandso,thisisalossydecomposition.
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ALossyDecomposition
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
FirstNormalForm
s Domainisatomicifitselementsareconsideredtobeindivisibleunits
q
Examplesofnonatomicdomains:
s ArelationalschemaRisinfirstnormalformifthedomainsofall
attributesofRareatomic
s Nonatomicvaluescomplicatestorageandencourageredundant
(repeated)storageofdata
q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
FirstNormalForm(Contd)
s Atomicityisactuallyapropertyofhowtheelementsofthedomainare
used.
q q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
GoalDeviseaTheoryfortheFollowing
s DecidewhetheraparticularrelationRisingoodform. s InthecasethatarelationRisnotingoodform,decomposeitintoa
setofrelations{R1,R2,...,Rn}suchthat
q q
s Ourtheoryisbasedon:
q q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
FunctionalDependencies
s Constraintsonthesetoflegalrelations. s Requirethatthevalueforacertainsetofattributesdetermines
uniquelythevalueforanothersetofattributes.
s Afunctionaldependencyisageneralizationofthenotionofakey.
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
FunctionalDependencies(Cont.)
s LetRbearelationschema
RandR
s Thefunctionaldependency
1 4 15 3 7
s Onthisinstance,ABdoesNOThold,butBAdoeshold.
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
FunctionalDependencies(Cont.)
s KisasuperkeyforrelationschemaRifandonlyifKR s KisacandidatekeyforRifandonlyif
q q
KR,and fornoK,R
s Functionaldependenciesallowustoexpressconstraintsthatcannot
bor_loan=(customer_id,loan_number,amount).
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
UseofFunctionalDependencies
s Weusefunctionaldependenciesto:
q
testrelationstoseeiftheyarelegalunderagivensetoffunctional dependencies.
specifyconstraintsonthesetoflegalrelations
s Note:Aspecificinstanceofarelationschemamaysatisfyafunctional
dependencyevenifthefunctionaldependencydoesnotholdonalllegal instances.
q
Forexample,aspecificinstanceofloanmay,bychance,satisfy amountcustomer_name.
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
FunctionalDependencies(Cont.)
s Afunctionaldependencyistrivialifitissatisfiedbyallinstancesofa
relation
q
Ingeneral,istrivialif
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ClosureofaSetofFunctional Dependencies
s GivenasetFoffunctionaldependencies,therearecertainother
functionaldependenciesthatarelogicallyimpliedbyF.
q
Forexample:IfABandBC,thenwecaninferthatAC
s ThesetofallfunctionaldependencieslogicallyimpliedbyFistheclosure
ofF.
s WedenotetheclosureofFbyF+. s F+isasupersetofF.
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
BoyceCoddNormalForm
ArelationschemaRisinBCNFwithrespecttoasetFof functionaldependenciesifforallfunctionaldependenciesinF+of theform whereRandR,atleastoneofthefollowingholds:
s istrivial(i.e.,) s isasuperkeyforR
ExampleschemanotinBCNF: bor_loan=(customer_id,loan_number,amount) becauseloan_numberamountholdsonbor_loanbutloan_numberis
notasuperkey
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
DecomposingaSchemaintoBCNF
s SupposewehaveaschemaRandanontrivialdependency
s Inourexample,
q q
=loan_number
=amount
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
BCNFandDependencyPreservation
s Constraints,includingfunctionaldependencies,arecostlytocheckin
practiceunlesstheypertaintoonlyonerelation
s Ifitissufficienttotestonlythosedependenciesoneachindividual
s BecauseitisnotalwayspossibletoachievebothBCNFand
dependencypreservation,weconsideraweakernormalform,known asthirdnormalform.
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ThirdNormalForm
s ArelationschemaRisinthirdnormalform(3NF)ifforall:
inF+ atleastoneofthefollowingholds:
q q q
(NOTE:eachattributemaybeinadifferentcandidatekey)
s IfarelationisinBCNFitisin3NF(sinceinBCNFoneofthefirsttwo
conditionsabovemusthold).
s ThirdconditionisaminimalrelaxationofBCNFtoensuredependency
preservation(willseewhylater).
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
GoalsofNormalization
s LetRbearelationschemewithasetFoffunctional
dependencies.
s DecidewhetherarelationschemeRisingoodform. s InthecasethatarelationschemeRisnotingoodform,
decomposeitintoasetofrelationscheme{R1,R2,...,Rn}such that
q q q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
HowgoodisBCNF?
s TherearedatabaseschemasinBCNFthatdonotseemtobe
sufficientlynormalized
s Consideradatabase
anyoneofwhichcanbethecoursesinstructor,andthesetofbooks, allofwhicharerequiredforthecourse(nomatterwhoteachesit).
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
HowgoodisBCNF?(Cont.)
course database database database database database database operatingsystems operatingsystems operatingsystems operatingsystems teacher Avi Avi Hank Hank Sudarshan Sudarshan Avi Avi Pete Pete classes
s Therearenonontrivialfunctionaldependenciesandthereforethe
book DBConcepts Ullman DBConcepts Ullman DBConcepts Ullman OSConcepts Stallings OSConcepts Stallings
relationisinBCNF
s Insertionanomaliesi.e.,ifMarilynisanewteacherthatcanteach
database,twotuplesneedtobeinserted
(database,Marilyn,DBConcepts) (database,Marilyn,Ullman)
DatabaseSystemConcepts5thEdition,July28,2005. 7.<number> Silberschatz,KorthandSudarshan
HowgoodisBCNF?(Cont.)
s Therefore,itisbettertodecomposeclassesinto:
course database database database operatingsystems operatingsystems course database database operatingsystems operatingsystems text
teacher Avi Hank Sudarshan Avi Jim book DBConcepts Ullman OSConcepts Shaw
teaches
Thissuggeststheneedforhighernormalforms,suchasFourth NormalForm(4NF),whichweshallseelater.
DatabaseSystemConcepts5thEdition,July28,2005. 7.<number> Silberschatz,KorthandSudarshan
FunctionalDependencyTheory
s Wenowconsidertheformaltheorythattellsuswhichfunctional
s Wethendevelopalgorithmstogeneratelosslessdecompositionsinto s Wethendevelopalgorithmstotestifadecompositionisdependency
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ClosureofaSetofFunctional Dependencies
s GivenasetFsetoffunctionaldependencies,therearecertainother
functionaldependenciesthatarelogicallyimpliedbyF.
q
Forexample:IfABandBC,thenwecaninferthatAC
s ThesetofallfunctionaldependencieslogicallyimpliedbyFistheclosure
ofF.
s WedenotetheclosureofFbyF+. s WecanfindallofF+byapplyingArmstrongsAxioms:
q q q
s Theserulesare
q q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Example
s R=(A,B,C,G,H,I)
s somemembersofF+
AH
AGI
CGHI
andaugmentingofCGHtoinferCGIHI, andthentransitivity
DatabaseSystemConcepts5thEdition,July28,2005. 7.<number> Silberschatz,KorthandSudarshan
ProcedureforComputingF+
s TocomputetheclosureofasetoffunctionaldependenciesF:
F+=F repeat foreachfunctionaldependencyfinF+ applyreflexivityandaugmentationrulesonf addtheresultingfunctionaldependenciestoF+ foreachpairoffunctionaldependenciesf1andf2inF+ iff1andf2canbecombinedusingtransitivity thenaddtheresultingfunctionaldependencytoF+ untilF+doesnotchangeanyfurther NOTE:Weshallseeanalternativeprocedureforthistasklater
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ClosureofFunctionalDependencies (Cont.)
s WecanfurthersimplifymanualcomputationofF+byusingthe
followingadditionalrules.
q q
TheaboverulescanbeinferredfromArmstrongsaxioms.
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ClosureofAttributeSets
s Givenasetofattributes,definetheclosureofunderF(denotedby
+)asthesetofattributesthatarefunctionallydeterminedbyunder F
s Algorithmtocompute+,theclosureofunderF
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ExampleofAttributeSetClosure
s R=(A,B,C,G,H,I) s F={AB
s (AG)+
4. result=ABCGHI (CGIandCGAGBCH)
s IsAGacandidatekey?
1. 2.
IsAGasuperkey?
1.
IsanysubsetofAGasuperkey?
1. 2.
DatabaseSystemConcepts5thEdition,July28,2005.
UsesofAttributeClosure
Thereareseveralusesoftheattributeclosurealgorithm:
s Testingforsuperkey:
q
s Testingfunctionaldependencies
q
s ComputingclosureofF
q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
CanonicalCover
s Setsoffunctionaldependenciesmayhaveredundantdependencies
thatcanbeinferredfromtheothers
q q
Forexample:ACisredundantin:{AB,BC} Partsofafunctionaldependencymayberedundant
s Intuitively,acanonicalcoverofFisaminimalsetoffunctional
dependenciesequivalenttoF,havingnoredundantdependenciesor redundantpartsofdependencies
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ExtraneousAttributes
s ConsiderasetFoffunctionaldependenciesandthefunctional
dependencyinF.
q
s Note:implicationintheoppositedirectionistrivialineachofthe
casesabove,sinceastrongerfunctionaldependencyalwaysimplies aweakerone
q
s Example:GivenF={AC,ABC}
s Example:GivenF={AC,ABCD}
q
DatabaseSystemConcepts5thEdition,July28,2005.
TestingifanAttributeisExtraneous
s s
TotestifattributeAisextraneousin
1. 2.
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
CanonicalCover
s AcanonicalcoverforFisasetofdependenciesFcsuchthat
q q q q
s TocomputeacanonicalcoverforF:
s Note:Unionrulemaybecomeapplicableaftersomeextraneousattributes
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ComputingaCanonicalCover
s
AisextraneousinABC
q
Yes:infact,BCisalreadypresent!
Setisnow{ABC,BC} CheckifACislogicallyimpliedbyABandtheotherdependencies
CisextraneousinABC
q
Yes:usingtransitivityonABandBC. CanuseattributeclosureofAinmorecomplexcases AB BC
7.<number> Silberschatz,KorthandSudarshan
Thecanonicalcoveris:
DatabaseSystemConcepts5thEdition,July28,2005.
LosslessjoinDecomposition
s ForthecaseofR=(R1,R2),werequirethatforallpossible
relationsronschemaR
r=R1(r)R2(r)
s AdecompositionofRintoR1andR2islosslessjoinifand
onlyifatleastoneofthefollowingdependenciesisinF+:
q q
R1R2R1 R1R2R2
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Example
s R=(A,B,C)
q
s R1=(A,B),R2=(B,C)
q
s R1=(A,B),R2=(A,C)
q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
DependencyPreservation
s LetFibethesetofdependenciesF+thatincludeonlyattributesin
Ri.
(F1F2Fn)+=F+
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
TestingforDependencyPreservation
s TocheckifadependencyispreservedinadecompositionofRinto
R1,R2,,Rnweapplythefollowingtest(withattributeclosuredonewith respecttoF)
q
s WeapplythetestonalldependenciesinFtocheckifadecompositionis
dependencypreserving
s Thisproceduretakespolynomialtime,insteadoftheexponentialtime requiredtocomputeF+and(F1F2Fn)+
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Example
s R=(A,B,C)
s RisnotinBCNF s DecompositionR1=(A,B),R2=(B,C)
q q q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
TestingforBCNF
s Tocheckifanontrivialdependency causesaviolationofBCNF
1.compute+(theattributeclosureof),and 2.verifythatitincludesallattributesofR,thatis,itisasuperkeyofR.
s Simplifiedtest:TocheckifarelationschemaRisinBCNF,itsufficesto
checkonlythedependenciesinthegivensetFforviolationofBCNF, ratherthancheckingalldependenciesinF+.
q
IfnoneofthedependenciesinFcausesaviolationofBCNF,then noneofthedependenciesinF+willcauseaviolationofBCNFeither.
s However,usingonlyFisincorrectwhentestingarelationina
decompositionofR
q
DatabaseSystemConcepts5thEdition,July28,2005.
TestingDecompositionforBCNF
s TocheckifarelationRiinadecompositionofRisinBCNF,
q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
BCNFDecompositionAlgorithm
result:={R}; done:=false; computeF+; while(notdone)do if(thereisaschemaRiinresultthatisnotinBCNF) thenbegin let beanontrivialfunctionaldependencythatholdsonRi suchthat RiisnotinF+, and=;
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ExampleofBCNFDecomposition
s R=(A,B,C)
s RisnotinBCNF(BCbutBisnotsuperkey) s Decomposition
q q
R1=(B,C) R2=(A,B)
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ExampleofBCNFDecomposition
s OriginalrelationRandfunctionaldependencyF
s Finaldecomposition
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
BCNFandDependencyPreservation
ItisnotalwayspossibletogetaBCNFdecompositionthatis dependencypreserving
s R=(J,K,L)
s RisnotinBCNF s AnydecompositionofRwillfailtopreserve
JKL ThisimpliesthattestingforJKLrequiresajoin
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ThirdNormalForm:Motivation
s Therearesomesituationswhere
q q
BCNFisnotdependencypreserving,and efficientcheckingforFDviolationonupdatesisimportant
s Solution:defineaweakernormalform,calledThird
NormalForm(3NF)
q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
3NFExample
s RelationR:
q
q q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Redundancyin3NF
s Thereissomeredundancyinthisschema s Exampleofproblemsduetoredundancyin3NF
q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Testingfor3NF
s Optimization:NeedtocheckonlyFDsinF,neednotcheckallFDsin
F+ .
s Useattributeclosuretocheckforeachdependency,ifisa
superkey.
s Ifisnotasuperkey,wehavetoverifyifeachattributeinis
containedinacandidatekeyofR
q
q q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
3NFDecompositionAlgorithm
LetFcbeacanonicalcoverforF; i:=0; foreachfunctionaldependencyinFcdo ifnoneoftheschemasRj,1jicontains thenbegin i:=i+1; Ri:= end ifnoneoftheschemasRj,1jicontainsacandidatekeyforR thenbegin i:=i+1; Ri:=anycandidatekeyforR; end return(R1,R2,...,Ri)
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
3NFDecompositionAlgorithm(Cont.)
s Abovealgorithmensures:
q q q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
3NFDecomposition:AnExample
s Relationschema:
cust_banker_branch=(customer_id,employee_id,branch_name,type)
s Thefunctionaldependenciesforthisrelationschemaare:
q q q
s Wefirstcomputeacanonicalcover
q q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
3NFDecompsitionExample(Cont.)
s
Theforloopgeneratesfollowing3NFschema:
Observethat(customer_id,employee_id,type)containsacandidatekeyof theoriginalschema,sonofurtherrelationschemaneedsbeadded
resultwillnotdependontheorderinwhichFDsareconsidered
Theresultantsimplified3NFschemais:
(customer_id,employee_id,type)
(customer_id,branch_name,employee_id)
DatabaseSystemConcepts5thEdition,July28,2005. 7.<number> Silberschatz,KorthandSudarshan
ComparisonofBCNFand3NF
s Itisalwayspossibletodecomposearelationintoasetofrelations
thatarein3NFsuchthat:
q q
thedecompositionislossless thedependenciesarepreserved
s Itisalwayspossibletodecomposearelationintoasetofrelationsthat
areinBCNFsuchthat:
q q
thedecompositionislossless itmaynotbepossibletopreservedependencies.
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
DesignGoals
s Goalforarelationaldatabasedesignis:
q q q
s Ifwecannotachievethis,weacceptoneof
q q
s Interestingly,SQLdoesnotprovideadirectwayofspecifying
functionaldependenciesotherthansuperkeys.
CanspecifyFDsusingassertions,buttheyareexpensivetotest
s Evenifwehadadependencypreservingdecomposition,usingSQL
wewouldnotbeabletoefficientlytestafunctionaldependencywhose lefthandsideisnotakey.
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
MultivaluedDependencies(MVDs)
s LetRbearelationschemaandletRandR.The
multivalueddependency
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
MVD(Cont.)
s Tabularrepresentationof
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Example
s LetRbearelationschemawithasetofattributesthatarepartitioned
into3nonemptysubsets.
Y,Z,W
s WesaythatYZ(YmultideterminesZ)
ifandonlyifforallpossiblerelationsr(R) then
<y1,z1,w1>rand<y1,z2,w2>r <y1,z1,w2>rand<y1,z2,w1>r
s NotethatsincethebehaviorofZandWareidenticalitfollowsthat
YZifYW
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Example(Cont.)
s Inourexample:
courseteacher coursebook
s Theaboveformaldefinitionissupposedtoformalizethe
s Note:
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
UseofMultivaluedDependencies
s Weusemultivalueddependenciesintwoways:
canconstructarelationsrthatdoessatisfythemultivalued dependencybyaddingtuplestor.
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
TheoryofMVDs
s Fromthedefinitionofmultivalueddependency,wecanderivethe
followingrule:
q
If,then
Thatis,everyfunctionaldependencyisalsoamultivalueddependency
s TheclosureD+ofDisthesetofallfunctionalandmultivalued
dependencieslogicallyimpliedbyD.
q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
FourthNormalForm
s ArelationschemaRisin4NFwithrespecttoasetDoffunctionaland
multivalueddependenciesifforallmultivalueddependenciesinD+ofthe form,whereRandR,atleastoneofthefollowinghold:
q q
istrivial(i.e.,or=R) isasuperkeyforschemaR
s Ifarelationisin4NFitisinBCNF
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
RestrictionofMultivaluedDependencies
s TherestrictionofDtoRiisthesetDiconsistingof
q q
whereRiandisinD+
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
4NFDecompositionAlgorithm
result:={R}; done:=false; computeD+; LetDidenotetherestrictionofD+toRi while(notdone) if(thereisaschemaRiinresultthatisnotin4NF)then begin letbeanontrivialmultivalueddependencythatholds onRisuchthatRiisnotinDi,and=; result:=(resultRi)(Ri)(,); end elsedone:=true; Note:eachRiisin4NF,anddecompositionislosslessjoin
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Example
s R=(A,B,C,G,H,I)
s SinceABandBHI,AHI,AI
FurtherNormalForms
s Joindependenciesgeneralizemultivalueddependencies
q
leadtoprojectjoinnormalform(PJNF)(alsocalledfifthnormal form)
s Aclassofevenmoregeneralconstraints,leadstoanormalform
calleddomainkeynormalform.
s Problemwiththesegeneralizedconstraints:arehardtoreasonwith,
andnosetofsoundandcompletesetofinferencerulesexists.
s Hencerarelyused
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
OverallDatabaseDesignProcess
s WehaveassumedschemaRisgiven
q
q q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ERModelandNormalization
s WhenanERdiagramiscarefullydesigned,identifyingallentities
s However,inareal(imperfect)design,therecanbefunctional
s Functionaldependenciesfromnonkeyattributesofarelationshipset
possible,butraremostrelationshipsarebinary
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
DenormalizationforPerformance
s Maywanttousenonnormalizedschemaforperformance s Forexample,displayingcustomer_namealongwithaccount_numberand
balancerequiresjoinofaccountwithdepositor aswellasdepositorwithallaboveattributes
q q q
s Alternative1:Usedenormalizedrelationcontainingattributesofaccount
s Alternative2:useamaterializedviewdefinedas
accountdepositor
q
Benefitsanddrawbackssameasabove,exceptnoextracodingwork forprogrammerandavoidspossibleerrors
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
OtherDesignIssues
s Someaspectsofdatabasedesignarenotcaughtbynormalization s Examplesofbaddatabasedesign,tobeavoided:
Insteadofearnings(company_id,year,amount),use
q
earnings_2004,earnings_2005,earnings_2006,etc.,allonthe schema(company_id,earnings).
AboveareinBCNF,butmakequeryingacrossyearsdifficult andneedsnewtableeachyear
company_year(company_id,earnings_2004,earnings_2005, earnings_2006)
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ModelingTemporalData
s Temporaldatahaveanassociationtimeintervalduringwhichthedata
arevalid.
s Asnapshotisthevalueofthedataataparticularpointintime s SeveralproposalstoextendERmodelbyaddingvalidtimeto
q q q
s Butnoacceptedstandard s Addingatemporalcomponentresultsinfunctionaldependencieslike
customer_idcustomer_street,customer_city nottohold,becausetheaddressvariesovertime
s AtemporalfunctionaldependencyXYholdsonschemaRifthe
functionaldependencyXYholdsonallsnapshotsforalllegal instancesr(R)
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
ModelingTemporalData(Cont.)
s Inpractice,databasedesignersmayaddstartandendtimeattributes
torelations
q
E.g.course(course_id,course_title) course(course_id,course_title,start,end)
Constraint:notwotuplescanhaveoverlappingvalidtimes Hardtoenforceefficiently
s Foreignkeyreferencesmaybetocurrentversionofdata,ortodataat
apointintime
q
E.g.studenttranscriptshouldrefertocourseinformationatthe timethecoursewastaken
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
EndofChapter
DatabaseSystemConcepts,5thEd.
Silberschatz,KorthandSudarshan Seewww.dbbook.comforconditionsonreuse
ProofofCorrectnessof3NF DecompositionAlgorithm
DatabaseSystemConcepts,5thEd.
Silberschatz,KorthandSudarshan Seewww.dbbook.comforconditionsonreuse
s 3NFdecompositionalgorithmisdependencypreserving(sincethereisa
Correctnessof3NFDecomposition Algorithm
relationforeveryFDinFc)
q q q
s Decompositionislossless
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Correctnessof3NFDecomposition Algorithm(Contd.)
Claim:ifarelationRiisinthedecompositiongeneratedbythe abovealgorithm,thenRisatisfies3NF.
s LetRibegeneratedfromthedependency s LetBbeanynontrivialfunctionaldependencyonRi.(Weneedonly
considerFDswhoserighthandsideisasingleattribute.) separately.
s Now,Bcanbeineitherorbutnotinboth.Considereachcase
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
s Case1:IfBin:
q q q
Correctnessof3NFDecomposition (Contd.)
Ifisasuperkey,the2ndconditionof3NFissatisfied Otherwisemustcontainsomeattributenotin SinceBisinF+itmustbederivablefromFc,byusingattribute closureon. Attributeclosurenothaveused.Ifithadbeenused,must becontainedintheattributeclosureof,whichisnotpossible,since weassumedisnotasuperkey. Now,using({B})andB,wecanderiveB (since,andBsinceBisnontrivial)
q
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Correctnessof3NFDecomposition (Contd.)
s Case2:Bisin.
q
q q
Q.E.D.
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Figure7.5:SampleRelationr
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Figure7.6
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Figure7.7
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Figure7.15:AnExampleof RedundancyinaBCNFRelation
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Figure7.16:AnIllegalR2Relation
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan
Figure7.18:RelationofPractice Exercise7.2
DatabaseSystemConcepts5thEdition,July28,2005.
7.<number>
Silberschatz,KorthandSudarshan