版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
數(shù)據(jù)庫原理
2003年/秋Chapter7
RelationalDatabaseDesign(c1)
12MainContentsBoyce-CoddNormalFormThirdNormalFormMultivaluedDependenciesFourthNormalFormOverallDatabaseDesignProcess3Boyce-CoddNormalForm
istrivial(i.e.,
)isasuperkeyforRArelationschemaRisinBCNFwithrespecttoasetFoffunctionaldependenciesif
forallfunctionaldependenciesinF+oftheform
,where
Rand
R,
atleastoneofthefollowingholds:4ExampleR=(A,B,C)
F={A
B
BC}
Key={A}RisnotinBCNFDecompositionR1=(A,B),R2=(B,C)R1
andR2inBCNFLossless-joindecompositionDependencypreserving5TestingforBCNFTocheckifanon-trivialdependency
inF+
causesaviolationofBCNF1.compute+(theattributeclosureof)2.verifythatitincludesallattributesofR,thatis,itisasuperkeyofR6SimplifiedTestingforBCNFTocheckifarelationschemaRwithagivensetoffunctionaldependenciesFisinBCNF,itsufficestocheckonly
thedependenciesinthegivenset
FforviolationofBCNF,ratherthancheckingalldependenciesinF+WecanshowthatifnoneofthedependenciesinFcausesaviolationofBCNF,thennoneofthedependenciesinF+willcauseaviolationofBCNFeither7NoTestonaDecompositionofRConsiderR(A,B,C,D),withF={AB,BC}DecomposeRintoR1(A,B)andR2(A,C,D)NeitherofthedependenciesinFcontainonlyattributesfrom(A,C,D)sowemightbemisleadintothinkingR2satisfiesBCNFInfact,dependencyA
CinF+showsR2isnotinBCNFHowever,usingonlyFisincorrectwhentestingarelationinadecompositionofR8BCNFDecompositionAlgorithm result:={R};done:=false;
computeF+;
while(notdone)do
if(thereisaschemaRi
inresultthatisnotinBCNF)
thenbegin
let
beanontrivialfunctionaldependency thatholdsonRisuchthat
Ri
isnotinF+,and
=;
result:=(result–Ri)(Ri–)(,);
end
elsedone:=true;Ri--Ri?9ExampleofBCNFDecompositionR=(branch-name,branch-city,assets,
customer-name,loan-number,amount)
F={branch-name
assetsbranch-city
loan-number
amountbranch-name}
Key={loan-number,customer-name}DecompositionR1=(branch-name,branch-city,assets)R2=(branch-name,customer-name,loan-number,amount)R3=(branch-name,loan-number,amount)R4=(customer-name,loan-number)Finaldecomposition
R1,R3,R410TestingDecompositionwithF+ArelationRiinadecompositionofRTestRiforBCNFwithrespecttotherestrictionofFtoRi(thatis,allFDsinF+thatcontainonlyattributesfromRi)11TestingDecompositionwithFArelationRiinadecompositionofRforeverysetofattributesRi,checkthat+(theattributeclosureof)eitherincludesnoattributeofRi-,orincludesallattributesofRiIftheconditionisviolatedbysomeinF,thedependency
(+-)Ri
canbeshowntoholdonRi,andRiviolatesBCNFWeuseabovedependencytodecomposeRi12BCNFandDP ItisnotalwayspossibletogetaBCNFdecompositionthatisdependencypreserving,’overnormalize’R=(J,K,L)
F={JK
L,L
K}
Twocandidatekeys=JKandJLRisnotinBCNFAnydecompositionofRwillfailtopreserveJK
L13MainContentsBoyce-CoddNormalFormThirdNormalFormMultivaluedDependenciesFourthNormalFormOverallDatabaseDesignProcess14Motivationof3NFTherearesomesituationswhereBCNFisnotdependencypreserving,andEfficientcheckingforFDviolationonupdatesis
importantSolutiondefineaweakernormalform,calledThirdNormalForm(3NF)15ThirdNormalFormArelationschemaRisinthirdnormalformifforall:
inF+
atleastoneofthefollowingholds:
istrivial(i.e.,
)isasuperkeyforREachattributeAin–iscontainedinacandidatekeyforRCanthecandidatekeybereplacedbysuperkey?Shouldeachattributebeinthesamecandidatekey?163NFandBCNFIfarelationisinBCNFitisin3NF(sinceinBCNFoneofthefirsttwoconditionsabovemusthold)ThirdconditionisaminimalrelaxationofBCNFtoensuredependencypreservation17Exampleof3NFR=(J,K,L) Twocandidatekeys,JKandJLRisin3NF
JK
L JKisasuperkey
L
K KiscontainedinacandidatekeyBCNFdecompositionhas(JL)and(LK)
F={JK
L,L
K}TestingforJK
Lrequiresajoin18Redundancyin3NFThereissomeredundancyinthisschemaEquivalenttoexampleinbook:Banker-schema=(branch-name,customer-name, banker-name) banker-namebranch-name branch-namecustomer-namebanker-nameb1 c1 k1b1 c2 k1b1 c1 k219Testingfor3NFTestingfor3NFhasbeenshowntobeNP-hardNeedtocheckonlyFDsinF,neednotcheckallFDsinF+Useattributeclosuretocheck,foreachdependency,ifisasuperkeyIfisnotasuperkey,wehavetoverifyifeachattributeiniscontainedinacandidatekeyofR203NFDecompositionAlgorithm LetFc
beacanonicalcoverforF; i:=0;
foreachfunctionaldependency
inFc
do
ifnoneoftheschemasRj,1j
icontains
thenbegin
i:=i+1;
Ri:=
end //endofifandfor
ifnoneoftheschemasRj,1j
icontainsacandidatekeyforR
thenbegin
i:=i+1;
Ri:=anycandidatekeyforR;
end //endofif
return(R1,R2,...,Ri)
213NFDecompositionAlgorithm(c1)ThepreviousalgorithmensureseachrelationschemaRi
isin3NFdecompositionisdependencypreservingandlossless-jointheresultisnotuniquelydefined22ExampleRelationschema
Banker-info-schema=(branch-name,customer-name,
banker-name,office-number)Thefunctionaldependencies
banker-name
branch-nameoffice-number
customer-namebranch-name
banker-nameThekey
{customer-name,branch-name}23Banker-info-schemato3NFTheforloopinthealgorithmcausesustoincludethefollowingschemasinourdecomposition:
Banker-office-schema= (banker-name,branch-name,office-number)
Banker-schema= (customer-name,branch-name, banker-name)
SinceBanker-schemacontainsacandidatekeyfor
Banker-info-schema,wearedonewiththedecompositionprocess24ComparisonofBCNFand3NFItisalwayspossibletodecomposearelationintorelationsin3NFandthedecompositionislossless,andthedependenciesarepreservedItisalwayspossibletodecomposearelationintorelationsinBCNFandthedecompositionislossless,howerveritmaynotbepossibletopreservedependencies25Examplein3NFJj1j2j3nullLl1l1l1l2Kk1k1k1k2Exampleofproblemsduetoredundancyin3NFR=(J,K,L)
F={JK
L,L
K}J=street,K=city,andL=zip26Problemsin3NF
Aschemathatisin3NFbutnotinBCNFhastheproblemsof
repetitionofinformation(e.g.,therelationshipl1,k1)needtousenullvalues(e.g.,torepresenttherelationshipl2,k2wherethereisnocorrespondingvalueforJ).27TradeoffinDesignGoalforarelationaldatabasedesignis:BCNFLosslessjoinDependencypreservationIfwecannotachievethis,weacceptoneofLackofdependencypreservationRedundancyduetouseof3NF28MainContentsBoyce-CoddNormalFormThirdNormalFormMultivaluedDependencies
FourthNormalFormOverallDatabaseDesignProcess29BeyondBCNFTherearedatabaseschemasinBCNFthatdonotseemtobesufficientlynormalizedConsideradatabase
classes(course,teacher,book)
suchthat(c,t,b)classesmeansthattisqualifiedtoteachc,andbisarequiredtextbookforc30Thedatabaseissupposedtolistforeachcoursethesetofteachersanyoneofwhichcanbethecourse’sinstructor,andthesetofbooks,allofwhicharerequiredforthecourse(nomatterwhoteachesit)AClassesInstancecourseteacherbookdatabasedatabasedatabasedatabasedatabasedatabaseoperatingsystemsoperatingsystemsoperatingsystemsoperatingsystemsAviAviHankHankSudarshanSudarshanAviAviJimJimDBConceptsUllmanDBConceptsUllmanDBConceptsUllmanOSConceptsShawOSConceptsShawcoursesteachersbooksC-T-B31Sincetherearenotnon-trivialdependencies,(course,teacher,book)istheonlykey,andthereforetherelationisinBCNF
Insertionanomalies(插入異常)ifSaraisanewteacherthatcanteachdatabase,twotuplesneedtobeinserted
(database,Sara,DBConcepts)
(database,Sara,Ullman)ProblemsinClassesTable32Therefore,itisbettertodecomposeclassesinto:courseteacherdatabasedatabasedatabaseoperatingsystemsoperatingsystemsAviHankSudarshanAviJimteachescoursebookdatabasedatabaseoperatingsystemsoperatingsystemsDBConceptsUllmanOSConceptsShawtextDecomposeClassesTable33MVDDefinitionLetRbearelationschemaandletRand
R
Themultivalueddependency(多值依賴)
holdsonRifinanylegalrelationr(R),forallpairsfortuplest1andt2inrsuchthatt1[]=t2[],thereexisttuplest3andt4inrsuchthat:
t1[]=t2[]=t3[]=t4
[]
t3[]=t1[]
t3[R–]=t2[R–]
t4[]=t2[]
t4[R–]=t1[R–]
34Tabularrepresentationof
t1[]=t2[]=t3[]=t4
[]t3[]=t1[]t3[R–]=t2[R–]t4[]=t2[]t4[R–]=t1[R–]35AnotherMVDDefinitionLetRbearelationschemawithasetofattributesthatarepartitionedinto3nonemptysubsets(非空子集)Y,Z,WWesaythatY
Z(Y
multidetermines
Z)
ifandonlyifforallpossiblerelationsr(R) <y1,z1,w1>rand<y1,z2,w2>r then
<y1,z1,w2>rand<y1,z2,w1>rTrivialmultivalueddependency,ifWisemptyNotethatsincethebehaviorofZandWareidenticalitfollowsthatYZifYW36MVDExampleInourexample:
courseteacher
coursebookTheaboveformaldefinitionissupposedtoformalizethenotionthatgivenaparticularvalueofY(course)ithasassociatedwithitasetofvaluesofZ(teacher)andasetofvaluesofW(book),andthesetwosetsareinsomesenseindependentofeachotherNote:IfY
ZthenY
ZIndeedwehave(inpreviousslide)Z1=Z2
R=YZ(R-Y-Z)37UseofMVDWeusemultivalueddependenciesintwoways:TotestrelationstodeterminewhethertheyarelegalunderagivensetoffunctionalandmultivalueddependenciesTospecifyconstraintsonthesetoflegalrelations.
WeshallthusconcernourselvesonlywithrelationsthatsatisfyagivensetofFDsandMVDs
38ConstructionIfarelationrfailstosatisfyagivenmultivalueddependency,wecanconstructarelationsrthatdoessatisfythemultivalueddependencybyaddingtuplestor
ExampleinbookBC-schema
39TheoryofMVDsFromthedefinitionofmultivalueddependency,wecanderivethefollowingrule:If,then Thatis,everyfunctionaldependencyisalsoamultivalueddependency40ClosureD+ofDTheclosure(閉包)D+ofDisthesetofallfunctionalandmultivalueddependencieslogicallyimpliedbyD
WecancomputeD+fromD,usingtheformaldefinitionsofFDsandMVDsWecanmanagewithsuchreasoningforverysimplemultivalueddependencies,whichseemtobemostcommoninpracticeForcomplexdependencies,itisbettertoreasonaboutsetsofdependenciesusingasystemofinferencerules41MainContentsBoyce-CoddNormalFormThirdNormalFormMultivaluedDependenciesFourthNormalFormOverallDatabaseDesignProcess42FourthNormalFormArelationschemaRisin4NFwithrespecttoasetDoffunctionalandmultivalueddependenciesifforallmultivalueddependenciesinD+oftheform
,where
Rand
R,atleastoneofthefollowinghold:
istrivial(i.e.,
or
=R)isasuperkeyforschemaRIfarelationisin4NFitisinBCNF43RestrictionofMVDsTherestrictionofDtoRiisthesetDiconsistingofAllfunctionaldependenciesinD+thatincludeonlyattributesofRiAllmultivalueddependenciesoftheform
(
Ri)where
Riand
isinD+
444NFDecompositionAlgorithmresult:={R};
done:=false;
computeD+;
LetDidenotetherestrictionofD+toRiwhile(notdone)
if(thereisaschemaRiinresultthatisnotin4NF)then
begin letbeanontrivialmultivalueddependency thatholdsonRisuchthatRiisnotinDi,and ;
result:=(result-Ri)(Ri
-)(,);
end
elsedone:=true;45DecompositionExampleR=(A,B,C,G,H,I) F={A
B,B
HI, CG
H}Risnotin4NFsinceA
BandAisnotasuperkeyforRDecomposition a)R1=(A,B) (R1isin4NF) b)R2=(A,C,G,H,I) (R2isnotin4NF) c)R3=(C,G,H) (R3isin4NF) d)R4=(A,C,G,I) (R4isnotin4NF)46DecompositionExample(c1) SinceA
BandB
HI,A
HI,A
I e)R5=(A,I) (R5isin4NF) f)R6=(A,C,G) (R6isin4NF)47MainContentsBoyce-CoddNormalFormThirdNormalFormMultivaluedDependenciesFourthNormalFormOverallDatabaseDesignProcess48OverallDatabaseDesignProcessWehaveassumedschemaRisgivenRcouldhavebeengeneratedwhenconvertingE-RdiagramtoasetoftablesRcouldhavebeenasinglerelationcontainingallattributesthatareofinterest(calleduniversalrelation泛關(guān)系)NormalizationbreaksRintosmallerrelations.Rcouldhavebeentheresultofsomeadhocdesignofrelations,whichwethentest/converttonormalform49ERModelandNormalizationWhenanE-Rdiagramiscarefullydesigned,identifyingallentitiescorrectly,thetablesgeneratedfromtheE-RdiagramshouldnotneedfurthernormalizationHowever,inareal(imperfect)designtherecanbeFDsfromnon-keyattributesofanentitytootherattributesoftheentity50ERModelandNormalization(c1)Exampleemployeeentitywithattributesdepartment-numberanddepartment-address,andanFDdepartment-numberdepartment-addressGooddesignwouldhavemadedepartmentanentityFDsfromnon-keyattributesofarelationshipsetpossible,butraremostrelationshipsarebinary51UniversalRelationDanglingtuplesTuplesthat“disappear”incomputingajoinLetr1(R1),r2(R2),….,rn(Rn)beasetofrelationsAtupleroftherelationriisadanglingtupleifrisnotintherelation: Ri(r1
r2…rn)Therelationr1
r2…rniscalledauniversalrelation
sinceitinvolvesalltheattributesinthe“universe”definedbyR1R2…Rn
52DanglingTuplesIfdanglingtuplesareallowedinthedatabase,insteadofdecomposingauniversalrelation,wemayprefertosynthesizeacollectionofnormalformschemasfromagivensetofattributesDanglingtuplesmayoccurinpracticaldatabaseapplicationsTheyrepresentincompleteinformation53ExampleforDanglingTuplesWemaywanttobreakupinformationaboutloansinto:(branch-name,loan-number)(loan-number,amount)(loan-number,customer-name)Universalrelationwouldrequirenullvalues,andhavedanglingtuples54UniversalRelationApproachAparticulardecompositiondefinesarestrictedformofincompleteinformationthatisacceptableinourdatabaseAbovedecompositionrequiresatleastone(至少一個(gè))ofcustomer-name,branch-nameoramountinordertoenteraloannumberwithoutusingnullvaluesRulesoutstoringofcustomer-name,amountwithoutanappropriateloan-number(sinceitisakey,itcan'tbenulleither!)55U
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 事件贊助與合作協(xié)議(2024版)3篇
- 2025年車隊(duì)車輛進(jìn)出口貿(mào)易合同范本3篇
- 2025銷售定金合同范本
- 2025廚師培訓(xùn)協(xié)議合同范本
- 2025年度酒店停車場車位租賃及客戶服務(wù)協(xié)議4篇
- 二零二五年度古建筑修復(fù)承包修建工程合同4篇
- 2025年度拆除工程風(fēng)險(xiǎn)評估與管理協(xié)議4篇
- 二零二四年度云計(jì)算產(chǎn)業(yè)委托擔(dān)保協(xié)議范本3篇
- 2025年度存量房買賣市場策略咨詢合同4篇
- 二零二四年度學(xué)生社會(huì)實(shí)踐與職業(yè)規(guī)劃研學(xué)旅行協(xié)議3篇
- 2024年蘇州工業(yè)園區(qū)服務(wù)外包職業(yè)學(xué)院高職單招職業(yè)適應(yīng)性測試歷年參考題庫含答案解析
- 人教版初中語文2022-2024年三年中考真題匯編-學(xué)生版-專題08 古詩詞名篇名句默寫
- 2024-2025學(xué)年人教版(2024)七年級(上)數(shù)學(xué)寒假作業(yè)(十二)
- 山西粵電能源有限公司招聘筆試沖刺題2025
- ESG表現(xiàn)對企業(yè)財(cái)務(wù)績效的影響研究
- 醫(yī)療行業(yè)軟件系統(tǒng)應(yīng)急預(yù)案
- 使用錯(cuò)誤評估報(bào)告(可用性工程)模版
- 《精密板料矯平機(jī) 第2部分:技術(shù)規(guī)范》
- 2024年高考全國甲卷英語試卷(含答案)
- 四年級上冊脫式計(jì)算300題及答案
- TQGCML 2624-2023 母嬰級空氣凈化器 潔凈空氣和凈化等級技術(shù)要求
評論
0/150
提交評論