您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 数据结构与算法 > 数据库Database Systems(3)
3DesignTheoryforRelationalDatabasesFunctionalDependenciesRulesAboutFunctionalDependenciesDesignofRelationalDatabaseSchemasDecomposition:TheGood,Bad,orUglyThirdNormalFormMultivaluedDependenciesAnAlgorithmforDiscoveringMVD’s3.1FunctionalDependencies(函数依赖)Itiscommonforaninitialrelationalschematohaveroomforimprovement,especiallybyeliminatingredundancy(消除冗余).Thereisadesigntheoryforrelationsthatletsusexamineadesigncarefullyandmakeimprovementsbasedonafewsimplepriciples.Ourdiscussionstartswith“functionaldependencies”,ageneralizationoftheideaofakeyforarelation.3.1.1DefinitionofFunctionalDependencyThefunctionaldependencyXAholdsonRifandonlyifforanylegalrelationsr(R),wheneveranytwotuplest1andt2ofragreeontheattributesX,theyalsoagreeontheattributeA.–Say“Xfunctionallydetermine(函数决定)A.”–Say“Afunctionallydependon(函数依赖于)X.”3.1.1DefinitionofFunctionalDependencyAfunctionaldependency(FD)onarelationRisanassertion:iftwotuplesofRagreeonalloftheattributesA1,A2,…,An,thentheymustalsoagreeonallofanotherlistofattributesB1,B2,…,Bm.WewritethisFDformallyasA1A2…AnB1B2…BmorA={A1,A2,…,An},B={B1,B2,…,Bm}AB3.1.1DefinitionofFunctionalDependencyExample3.1:LetusconsidertherelationMovies(title,year,length,genre,studioName,starName)titleyearlengthgenrestudioNamestarNameStarWarsStarWarsStarWarsGoneWiththeWindWayne’sWorldWayne’sWorld1977197719771939199219921241241242319595SciFiSciFiSciFidramacomedycomedyFoxFoxFoxMGMParamountParamountCarrieFisherMarkHamillHarrisonFordVivienLeighDanaCarveyMikeMeyerstitleyearlengthgenrestudioNameconsider:titleyearstarName?3.1.1DefinitionofFunctionalDependencyRememberthataFD,likeanyconstraint,isanassertionabouttheschemaofarelation,notaboutaparticularinstance.Example:ConsiderR(A,B)withthefollowinginstance.Onthisinstance,ABdoesNOThold,butdoesBAhold?ABa1b1a2b3a1b23.1.1DefinitionofFunctionalDependencyCorollary(推论)1:–A1A2…AnB1–A1A2…AnB2–…–A1A2…AnBmiff(ifandonlyif)–A1A2…AnB1B2…BmCorollary2:–AA3.1.1DefinitionofFunctionalDependencyConsiderthefunctionaldependenciesinrelationstudents(Sno,Sname,gender,depid,dorm,Cno,Cname,score).SnoCnoscoreSnoSnamegenderdepiddormdepiddorm,CnoCname分析一个具体关系中的函数依赖:–根据属性之间的语义关系分析函数依赖。–Example:Borrow(date,bookid,Sno)–尽可能使函数依赖式的左面最小化,而右面最大化。SnoSnamegender?Snamegender?SnoSnamegender?Snoscore?SnoCno?SnoCnoscore?3.1.1DefinitionofFunctionalDependencyThreecasesofassertingfunctionaldependencies:–IftwotupleshavethesamevaluesintheirAcomponents,andtheyalsohavethesamevaluesintheirBcomponents,thenABholds.–IftwotupleshavethesamevaluesintheirAcomponents,buttheyhavenotthesamevaluesintheirBcomponents,thenABdoesnothold(AB).–Ifanytwotuplescan’thavethesamevaluesintheirAcomponents,thenABholds.3.1.1DefinitionofFunctionalDependency常见术语:部分函数依赖:若XY,且存在X的真子集X’,X’Y,则称Y对X部分函数依赖。完全函数依赖:若XY,且Y对X不是部分函数依赖,则称Y对X是完全函数依赖。传递函数依赖:若XY,YZ,且YX不成立,则称Z对X是传递函数依赖。3.1.2KeysofRelationsKey:Wesayasetofoneormoreattributes{A1,A2,...,An}isakeyforarelationRif:–{A1,A2,...,An}functionallydetermineallotherattributesoftherelationR.(superkey)ItisimpossiblefortwodistincttuplesofRtoagreeonallofA1,A2,...,An.–Nopropersubset(真子集)of{A1,A2,...,An}canfunctionallydetermineallotherattributesofR.(minimal)3.1.2KeysofRelationsKeyoftherelationMovies(title,year,length,genre,studioName,starName):–{title,year}?–{title,year,starName}?IfABholdsinR(A,B,C)–thekeysofR:–AC3.1.2KeysofRelationsCandidatekey(候选键):–Sometimesarelationhasmorethanonekey.–Allkeysofarelationarecandidatekeys.Primarykey(主键):–Itiscommontodesignateoneofthekeysastheprimarykey.Incommercialdatabasesystems,thechoiceofprimarykeycaninfluence(影响)someimplementationissues.–ThetheoryofFD’sgavesnospecialroleto“primarykeys.”3.1.3Superkeys(超键)Superkeys:–Supersetofakey.–Asetofattributesthatcontainsakey.–Thoseattributesfunctionallydetermineallotherattributesoftherelation.Therelationshipbetweenkeysandsuperkeys:–Keysaresuperkeys.{title,year,starName}–Somesuperkeysarenotkeys.{title,year,length,starName}3.1FunctionalDependencies(函数依赖)Exercises:Considerthefollowingrelationalschema:Sale(clerk,store,city,date,item#,size)//recordsthataclerksoldanitemonaparticulardayItem(item#,size,price)//recordspricesandavailablesizesforitemsMakethefollowingassumptions(假定),andonlytheseassumptions,abouttherealworldbeingmodeled:–Eachclerkworksinonestore.–Eachstoreisinonecity.–Agivenitem#alwayshasthesameprice,regardlessofsize.–Eachitemisavailableinoneormoresizes.Problems:–Basedontheassumptionsabove(andnoothers),specifyanappropriatesetoffunctionaldependenciesforrelationsSaleandItem.–Basedontheassumptionsabove(andnoothers),specifyallkeysforrelationsSaleandItem,respectively.3.1FunctionalDependencies(函数依赖)Answers:–Basedontheassumptionsabove(andnoothers),specifyanappropriatesetoffunctionaldependenciesforrelationsSaleandItem.clerk-store,store-city,item#-price–Basedontheassumptionsabove(andnoothers),specifyallkeysforrelationsSaleandItem,respectively.keyofsale:{clerk,date,item#,size}keyofitem:{item#,size}3.2RulesAboutFunctionalDependenciesReasoningaboutfunctionaldependencies–Supposewearetold
本文标题:数据库Database Systems(3)
链接地址:https://www.777doc.com/doc-3632286 .html