下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
《数据库处理》复习要点及参考答最近更新时间第一章Access2007(第一次作业 复习要 第二章结构化查询语言简介(第二次作业 复习要 Marcia干洗店项目练 第三章关系模型和规范化(第三次作业 复习重 Marcia干洗店项目练 第四 复习重 第五章E-R图(第四次作业 复习重 Marcia干洗店项 第六章数据库设计(第五次作业 复习重 Marcia洗衣店项目练 第七章数据库创建、视图、触发器(第六次作业 复习重 第十章用SQLServer2008管理数据库触发器、过 第八章数据库再设 第九章管理多用户数据 第一 Access2007(第一次作业元数据Access的使用CreateaAccessdatabasenamedAnswerstotheProjectQuestions1.61-1.70arecontainedinthedatabaseDBPe11-IM-Ch01-WPC.accdb,whichisavailableonthetext’sWebsite( ThedatabaseiscreatedasdescribedinAppendixA.Thetwotablestobecreatedare:DEPARTMENT(DepartmentName,BudgetCode,OfficeNumber,Phone)EMPLOYEE(EmployeeNumber,Name,LastName,Department,Phone,)WhereAnunderlinedcolumnnameindicatesthetablekey(primarykey)ofthetable,andanitalicizedcolumnindicatesaforeignkeylinkinotables.Figure1-26showsthecolumncharacteristicsfortheWPCDEPARTMENTtable.Usingthecolumncharacteristics,createtheDEPARTMENTtableintheWPC.accdbdatabase.Figure1-27showsthedatafortheWPCDEPARTMENTtable.UsingDatasheetview,enterthedatashowninFigure1-27intoyourDEPARTMENTtable.Figure1-28showsthecolumncharacteristicsfortheWPCEMPLOYEEtable.Usingthecolumncharacteristics,createtheEMPLOYEEtableintheWPC.accdbdatabase.CreatetherelationshipandreferentialintegrityconstraintbetweenDEPARTMENTandEMPLOYEE.Enableenforcingofreferentialintegrityandcascadingofdataupdates,butdonotenablecascadingofdatafromdeletedrecords.UsingtheAccessformwizard,createadatainputformfortheEMPLOYEEtableandnameitWPCEmployeeDataForm.Makeanyadjustmentsnecessarytotheformsothatalldatadisplayproperly.UsethisformtoentertherestofthedataintheEMPLOYEEtableshowninFigure1-29intoyourEMPLOYEEtable.UsingtheAccessreportwizard,createareportnamedWedgewoodPacificCorporationEmployeeReportthatpresentsthedontainedinyourEMPLOYEEtablesortedbyemployeelastnameandthenbyemployeename.Makeanyadjustmentsnecessarytothereportsothatallheadingsanddatadisplayproperly.Printacopyofthisreport.Toproducethereportasshownbelow,someworkintheReportDesignviewisnecessary–takethetimetoshowyourstudentshowtomodifyreportformatsinReportDesignview.UsingtheAccessformwizard,createaformthathasallofthedatafrombothtables.Whenaskedhowyouwanttoviewyourdata,selectbyDEPARTMENT.Choosethedefaultoptionsforotherquestionsthatthewizardasks.OpenyourformandpagethroughyourToproducethereportasshownbelow,someworkintheFormDesignviewisnecessary–takethetimetoshowyourstudentshowtomodifyreportformatsinFormDesignview.UsingtheAccessreportwizard,createareportthathasallofthedatafrombothtables.Whenaskedhowyouwanttoviewyourdata,selectbyDEPARTMENT.ForthedontainedinyourEMPLOYEEtableinthereport,specifythatitwillbesortedbyemployeelastnameandthenbyemployeename.Makeanyadjustmentsnecessarytothereportsothatallheadingsanddatadisplayproperly.Printacopyofthisreport.Toproducethereportasshownbelow,someworkintheReportDesignviewisnecessary–takethetimetoshowyourstudentshowtomodifyreportformatsinReportDesignview.Explain,tothelevelofdetailinthischapter,whatisgoingonwithinAccessinProjectQuestions1.67,1.68,1.69,and1.70.What ponentcreatedtheformandreport?Whereisthedatastored?WhatroledoyouthinkSQLisplaying?AccessusesSQLSELECTstatementstoquerythedatabasetablesforthedatatobedisplayedintheformsandthereport.Theresultsofthequeryarestoredinatemporarytablecreatedtoholdthisdata,andthistableisthesourceofthedatadisplayedintheformandthereport.SQLisusedtogatherthedataneededfordisplayintheformandreport.第二章结构化查询语言简介(第二次作业SQL发现数据模式实验TheChangeCloseon TDayOfWeeK=The um,andaverageChangeCloseon MIN(ChangeClose)ASMinFridayChangeClose,MAX(ChangeClose)ASMaxFridayChangeClose,AVG(ChangeClose)ASAverageFridayChangeClose TDayOfWeeK=TheaverageChangeClosegroupedbyTYear.Show TYear,AVG(ChangeClose)ASAverageChangeClose GROUPBYTYearORDERBYTYear;TheaverageChangeClosegroupedbyTYearandTMonth.ShowTYearandSinceTYearandTMontharebeingdisplayed,itmakessensetosorttheresultsbyTYearandTMonthalthoughthisisnotexplicitlystatedinthequestion. TYear,AVG(ChangeClose)ASAverageChangeClose GROUPBYTYear,TMonthORDERBYTYear,TMonth;Unfortunay,thetableNDXdoesnotcontainanumericvalueofthemonth,soinordertosortthemonthscorrectly,weneedaTMonthNumberwhichhasacolumncontainingarepresentativenumberforeaonth(January=1,February=2,etc.).IntheDBPe11-NDX.accdbandDBPe11-IM-Ch02-NDX.accdbdatabases,thiscolumnisincludedinatablenamedNDX_FULL. TYear,AVG(ChangeClose)ASAverageFridayChangeClose GROUPBYTYear,TMonth,TMonthNumberORDERBYTYear,TMonthNumber;TheaverageChangeClosegroupedbyTYear,TQuarter,TMonthshownindescendingorderoftheaverage(youwillhavetogiveanametotheaverageinordertosortbyit).ShowTYear,TQuarter,andTMonth.Notethatmonthsappearinalphabeticalandnotcalendarorder.Explainwhatyouneedtodotoobtainmonthsincalendarorder. TYear,TQuarter,AVG(ChangeClose)ASAverageChangeClose GROUPBYTYear,TQuarter,TMonthORDERBYAverageChangeCloseDESC;Unfortunay,asdiscussedabove,AccesscannotprocesstheORDERBYclausecorrectlywhenanSQLbuilt-infunctionisused.Thecorrectresult,obtainedfromSQLServer2008,Inordertoobtainthemonthsincalendarorder,wewouldhavetouseanumericalvalueforeaonth(1,2,3,…,12)andsortbythosevalues. ThedifferencebetweentheumChangeCloseandtheminimumChangeClosegroupedbyTYear,TQuarter,TMonthshownindescendingorderofthedifference(youwillhavetogiveanametothedifferenceinordertosortbyit).ShowTYear,TQuarter,andTMonth. TYear,TQuarter,(MAX(ChangeClose)–MIN(ChangeClose))ASDifChangeClose GROUPBYTYear,TQuarter,TMonthORDERBYDifChangeCloseDESC;Unfortunay,asdiscussedabove,AccesscannotprocesstheORDERBYclausecorrectlybecauseitcontains iasedcomputedresult.Thecorrectresult,obtainedfromSQLServer2008,TheaverageChangeClosegroupedbyTYearshownindescendingorderoftheaverage(youwillhavetogiveanametotheaverageinordertosortbyit).Showonlygroupsforwhichtheaverageispositive. AVG(ChangeClose)ASAverageChangeClose GROUPBY AVG(ChangeClose)>0ORDERBYAverageChangeCloseDESC;Unfortunay,asdiscussedabve, AccesscannotprocesstheORDERBYclausecorrectlybecauseitcontains iasedcomputedresult.Thecorrectresult,obtainedfromSQLServer2008,Displayasinglefieldwiththedateintheform:day/monthy/year.Donotbeconcernedwithtrailingblanks.ThesolutiontothisquestionrequiresthestudenttousetheDBMShelpfunctionorotherreferencestofigureoutaconversionfunctiontoconvertthenumericaldayofthemonthtoacharacterstringthatcanbecombinedwithotherdataalreadyincharacterformat.ThetableNDXdoesnothaveanumericvalueformonth,sothenamesofthemonthswillappearinthesolution.Ifwewantthenumericvalueofthemonth,wecouldusetheNDX_Fulltable,whichhasanumericvalue.Wewouldneedtousethedatatypeconversiononthisfieldaswell.TheSQLStatementusingSQLServer2008characterstringfunctions CAST(TDayOfMonthASChar(2))+'/'TMonth+'/'+TYearASDisplayDate TDayOfMonth= TMonth='September' TYear='2001';TheSQLServer2008resultTheSQLStatement Access2007characterstringfunctionsSELECTCStr(TDayOfMonth)+'/TMonth+'/'+TYearASDisplayDate WHERENDX.TDayOfMonthANDNDX.TMonth='September'ANDNDX.TYear='2001';TheAccess2007resultItispossiblethatvolume(thenumberofsharestraded)hassomecorrelationwiththedirectionofthestockmarket.UsetheSQLyouhavelearnedinthischaptertoinvestigatethatpossibility.DevelopatleastfivedifferentSQLstatementsinyourinvestigation.Ifvolumeiscorrelatedwiththedirectionofthestockmarket,thismeansthatthereshouldbePOSITIVECORRELEATION:Highervolumewhenthemarketcloseshigher,NEGATIVECORRELATION:HighervolumewhenthemarketclosesWhendoesthemarketclosehigher?WhenNDX.ChangeCloseis TMonth,TDayOfMonth,TYear,ChangeClose ChangeClose>Whendoesthemarketcloselower?WhenNDX.ChangeCloseis TMonth,TDayOfMonth,TYear,ChangeClose ChangeClose<Now,whataretheaveragepositiveandnegative AVG(ChangeClose)ASAvgPositiveChange ChangeClose> AVG(ChangeClose)ASAvgNegativeChange ChangeClose<Now,whataretheaveragevolumesassociatedwiththepositiveandnegative AVG(ChangeClose)ASAvgPositiveChange,AVG(Volume)ASAvgVolumeOnPositiveChange ChangeClose> AVG(ChangeClose)ASAvgNegativeChange,AVG(Volume)ASAvgVolumeOnNegativeChange ChangeClose<So,whenthereisapositive,orupward,changeinthemarketwehaveaagevolumeof641417.1117318sharestraded,andwhenwehaveanegative,ordownward,changeinthemarketwehaveaagevolumeof6742500.66698428shares.Thesenumbersdonotlooksignificantlydifferent,wewillconcludethatthereisnocorrelationbetweenthedirectionofthemarketmovementandthevolumeofsharestraded(ifwewantedtobemoreformal,wecoulduseastatisticalprocedureanddoahypothesistestastowhetherornotthereisreallyastatisticallysignificantdifferencebetweenthesetwonumbers).MarciaMarcia'sDryCleaningisanupscaledrycleanersinawell-to-dosuburbanneighborhood.Marciamakesherbusinessstandoutfromthecompetitionbyprovidingsuperiorcustomerservice.Shewantstokeeptrackofeachofhercustomersandtheirorders.Ultimay,shewantstonotifythemthattheirclothesarereadyvia.Toprovidethisservice,shehasdevelopedaninitialdatabasewithseveraltables.Threeofthosetablesarethefollowing:CUSTOMER(CustomerID,Name,LastName,Phone,)ORDER(Number,CustomerNumber,DateIn,DateOut,TotalAmt)ORDER_ITEM(Number,ItemNumber,Item,ty,UnitPrice)Showalldataineachofthe NotethetwocustomersbothnamedBetsy ListthePhoneandLastNameofall Phone,LastName ListthePhoneandLastNameforallcustomerswithaNameof Phone,LastName Name=ListthePhone,DateIn,andDateOutofallordersinexcessof注意:由于ORDER是SQL括起来 Phone,DateIn,DateOut CUSTOMER,[ORDER] TotalAmount CUSTOMER.CustomerID=ListthePhoneandNameofallcustomerswhosenamestartswithThecorrectSQL-92statement,whichusesthewildcard%, NameLIKEHowever,MSAccessusesthewildcard*,whichgivesthefollowingSQL NameLIKEListthePhoneandNameofallcustomerswhoselastnameincludesthecharacters,'cat'.ThecorrectSQL-92statement,whichusesthewildcard%, LastNameLIKEHowever,MSAccessusesthewildcard*,whichgivethefollowingSQL LastNameLIKEListthePhone,Name,andLastNameforallcustomerswhosesecondandthirdcharactersofphonenumberis23.Notethatsincethephonenumbersinthisdatabaseincludetheareacode,wearefindingphonenumberswith‘23’asthesecondandthirdnumbersintheareacode.Wecould,offcourse,writestatementstofind‘23’intheprefixorinthe4-digitsequenceportionofthephonenumber.ThecorrectSQL-92statement,whichusesthewildcards%and_, Name,LastName PhoneLIKEHowever,MSAccessusesthewildcards*and?,whichgivethefollowingSQL Name,LastName PhoneLIKEDeterminetheumandminimum注意:由于ORDER是SQL括起来 MAX(TotalAmt)ASMaxTotalAmount,MIN(TotalAmt)ASMinTotalAmount Determinetheaverage注意:由于ORDER是SQL括起来 AVG(TotalAmt)ASAvgTotalAmount Countthenumberof Count(*)ASNumberOfCustomers GroupcustomersbyLastNameandthenby GROUPBYCountthenumberofcustomershavingeachcombinationofLastNameand COUNT(*)AS GROUPBY ShowtheNameandLastNameofallcustomerswhohavehadanorderwithTotalAmountgreaterthan100.Useasubquery.PresenttheresultssortedbyLastNameinascendingorderandthen Nameindescendingorder.注意:由于ORDER是SQL括起来 Name,LastName CustomerID(SELECTCustomerNumberFROM[ORDER]WHERETotalAmount>100)ORDERBYLastName,NameDESC;ShowtheNameandLastNameofallcustomerswhohavehadanorderwithTotalAmountgreaterthan100.Useajoin.PresenttheresultssortedbyLastNameinascendingorderandthenNameindescendingorder.注意:由于ORDER是SQL括起来 Name,LastName CUSTOMER,[ORDER] CUSTOMER.CustomerID=[ORDER].CustomerNumber TotalAmount>100ORDERBYLastName,NameShowtheNameandLastNameofallcustomerswhohavehadanorderwithanItemnamed“DressShirt”.Useasubquery.PresenttheresultssortedbyLastNameinascendingorderandthen Nameindescendingorder.注意:由于ORDER是SQL括起来 Name,LastName CustomerID(SELECTCustomerNumber Number(SELECTNumberFROMORDER_ITEMWHEREItem='DressShirt'))ORDERBYLastName,NameDESC;ShowtheNameandLastNameofallcustomerswhohavehadanorderwithanItemnamed“DressShirt”.Useajoin.PresenttheresultssortedbyLastNameinascendingorderandthenNameindescendingorder.注意:由于ORDER是SQL括起来 Name, CUSTOMER,[ORDER], CUSTOMER.CustomerID=[ORDER].CustomerNumber [ORDER].Number=ORDER_ITEM.Number ORDER_ITEM.Item='DressShirt'ORDERBYLastName,NameShowtheName,LastNameandTotalAmountofallcustomerswhohavehadanorderwithanItemnamed“DressShirt”.Useajoinwithasubquery.PresentresultssortedbyLastNameinascendingorderandthenNameindescendingorder.注意:由于ORDER是SQL括起来 Name,LastName,TotalAmount CUSTOMER,[ORDER] CUSTOMER.CustomerID=[ORDER].CustomerNumber [ORDER].NumberIN(SELECTNumberFROMORDER_ITEMWHEREItem='DressShirt')ORDERBYLastName,NameDESC;第三章关系模型和规范化(第三次作业1NF1NF-关系的特征-应用,哪里不满足2NF(不存在非主属性对候选键的部分依赖)R(A,B,N,O,P)A->N2NF。,,BCNF--将表转化为BCNF3.13ConsidertheSTAFF_MEETING(EmployeeName,ProjectName,Therowsofthistablerecordthefactthatanemployeefromaparticularprojectattendedameetingonthegivendate.Assumethataprojectmeetsatmostonceperday.Also,assumethatonlyoneemployeerepresentsagivenproject,butthatemployeescanbeassignedtomultipleprojects.StatethefunctionalSincetherecanonlybeoneprojectmeetingforaparticularprojectperday,we(ProjectName,Date)→Sincethereisonlyoneemployeeassignedtothemeetingsforeachproject,weProjectName→TransformthistableintooneormoretablesinBCNF.Statetheprimarykeys,candidatekeys,foreignkeys,andreferentialintegrityconstraints.(ProjectName,Date)→EmployeeNameProjectName→EmployeeNameSTAFF_MEETINGCANDIDATEKEYS:(ProjectName,IseverydeterminantacandidateNO,thereforetherelationisNOTinTherefore,moveProjectName→EmployeeintoanothertableSTAFF_MEETING_2(ProjectName,Date)STAFF_MEETING_EMPLOYEE(ProjectName,EmployeeName)STAFF_MEETING_2FUNCTIONALDEPENDENCIES:(ProjectName,Date)→(ProjectName,IseverydeterminantacandidateYES,thereforetherelationisinProjectName→EmployeeNameSTAFF_MEETING_2CANDIDATEKEYS:IseverydeterminantacandidateYES,thereforetherelationisinBCNFThetablesarenowallinBCNF.FINALSETOFSTAFF_MEETING_2(ProjectName,Date)STAFF_MEETING_EMPLOYEE(ProjectName,EmployeeName)REFENTIALINTEGRITYCONSTRAINTS:ProjectNameinSTAFF_MEETING_EMPLOYEEmustexistinIsyourdesigninpartbanimprovementovertheoriginaltable?Whatadvantagesanddisadvantagesdoesithave?Yes,thedesigninpartbisanimprovementovertheoriginaltable.TheadvantageisthatitisnotsubjecttomodificationanomaliessincealltablesareinBCNF.Theonlydisadvantageithasisthattheremustbestaffmeetingdataentered(ProjectNameandDateinSTAFF_MEETING_2)beforeanEmployeeNamecanbeenteredinSTAFF_MEETING_EMPLOYEE.Thismayseemillogicaltosomeoneenteringthedata.ConsidertheSTUDENT(Number,Name,Dorm,RoomType,DormCost,Club,ClubCost,Sibling,Assumethatstudentspaydifferentdormcosts,dependingonthetypeofroomtheyhave,butthatallmembersofaclubpaythesamecost.AssumethatstudentscanhavemultipleStateanymultivaluedWewillassumethatNumber→Namewherenameisnotunique(i.e.,theremaybemorethanone“JohnSmith”,eachwithadifferentstudentnumber).Thenthemultivalueddependenciesare:Number→→ClubNumber→→SiblingNumber→→NicknameNote:WecannotassumethatName→→NicknamebecauseNameisnotunique.Forexample,oneJohnSmithmayhavethenickname“Johnny”whileanotherJohnSmithhasthenickname”Joe.”IfName→→NicknamethenJohnSmith→→(“Johnny”,“Joe”)whichmeansthatbothnicknamesapplytobothJohnSmiths.Butthisisnotthecase–eachJohnSmithhasonlyonenickname,andtheyarenotthesame.StatethefunctionalWewillassumethatNumber→Namewherenameisnotunique(i.e.,theremaybemorethanoneJohnSmith,eachwithadifferentstudentnumber).Thenthefunctionaldependenciesare:Number→NameNumber→DormNumber→RoomTypeRoomType→DormCostClub→ClubCostNote:ThisassumesthatonlyRoomType→DormCost–thatis,thecostofacertaintypeofdormroomisthesamenomatterwhatdormthestudentislivingin.ternateassumptionwouldbethat(Dorm,RoomType)→DormCost,wherethecostofthetypeofdormroomvariesfromdormtodorm.TransformthistableintotwoormoretablessuchthateachtableisinBCNFandin4NF.Statetheprimarykeys,candidatekeys,foreignkeys,andreferentialintegrityWe’llmovetheobviousmultivalueddependenciesintotheirowntables,andthencheckforBCNF.IFwehaveBCNFandnomultivalueddependencies,wealsohave4NF:STEPONE:MOVEMULTIVALUEDDEPENDENCIESINTOSEPARATESTUDENT_2(Number,Name,Dorm,RoomType,DormCost)STUDENT_CLUB_MEMBERSHIP(Number,Club,ClubCost)STUDENT_SIBLING(Number,Sibling)STUDENT_NICKNAME(Number,Nickname)STEPTWO:CHECKEACHOFTHERESULTINGTABLESFORBNCF:STEPTWO(A):CHECKSTUDENTSTUDENT_2FUNCTIONALSTUDENT_2(Number,Name,Dorm,RoomType,Number→NameNumber→DormNumber→RoomTypeRoomType→DormCostSTUDENT_2CANDIDATEIseverydeterminantacandidateNO,RoomTypeisNOTacandidatekey.ThereforetherelationisNOTinBCNF.Therefore,moveRoomType→DormCostintoanothertableSTUDENT_3(Number,Name,Dorm,RoomType)DORM_RATE(RoomType,DormCost)STEPTWO(A)(1):CHECKSTUDENT_3:STUDENTFUNCTIONALDEPENDENCIES:STUDENT_3(Number,Name,Dorm,Number→NameNumber→DormNumber→RoomTypeSTUDENTCANDIDATEIseverydeterminantacandidateYES,ThereforeSTUDENT_3isinBNCF.STEPTWO(A)(2):CHECKSTUDENT:DORM_RATEFUNCTIONALDEPENDENCIES:DORM_RATE(RoomType,RoomType→DormCostDORM_RATECANDIDATEKEYS:IseverydeterminantacandidateYES,ThereforeDORM_RATEisinBNCF.STEPTWO(B):CHECKSTUDENT_CLUB_MEMBERSHIPSTUDENT_CLUB_MEMBERSHIP(Number,Club,(Number,Club)→ClubCostClub→ClubCost(Number,IseverydeterminantacandidateNO,ClubisnotacandidateTherefore,moveClub→ClubCostintoanotherSTUDENT_CLUB_MEMBERSHIP(Number,STUDENT_CLUB_COST(Club,STEPTWO(B)(1):CHECKSTUDENT_CLUB_MEMBERSHIP:STUDENT_CLUB_MEMBERSHIPFUNCTIONALDEPENDENCIES:STUDENT_CLUB_MEMBERSHIP(Number,Club) NumberdoesnotdetermineClub,andClubdoesnotdetermineNumber.(Number,IseverydeterminantacandidateYES,inthiscasethereareNOdeterminants,butthismeetsthecriteria!ThereforeSTUDENT_CLUB_MEMBERSHIPisinBNCF.Arethefieldsofthemultivalueddependencytheonlyfieldsinthistable?YES,ThereforeSTUDENT_CLUB_MEMBERSHIPisinSTEPTWO(B)(2):CHECKSTUDENT_CLUB_COST:STUDENT_CLUB_COSTFUNCTIONALDEPENDENCIES:STUDENT_CLUB_COST(Club,Club→STUDENT_CLUB_COSTCANDIDATEIseverydeterminantacandidateYES,ThereforeSTUDENT_CLUB_COSTisinBNCF.STEPTWO(C):CHECKSTUDENT_SIBLINGSTUDENT_SIBLING(Number, NumberdoesnotdetermineSibling,andSiblingdoesnotdetermineNumber.(Number,IseverydeterminantacandidateYES,inthiscasethereareNOdeterminants,butthismeetsthecriteria!ThereforeSTUDENT_SIBLINGisinArethefieldsofthemultivalueddependencytheonlyfieldsinthisYES,ThereforeSTUDENT_SIBLINGisin4NF.STEPTWO(D):CHECKSTUDENT_NCIKNAMESTUDENT_NICKNAMEFUNCTIONALDEPENDENCIES:STUDENT_NICKNAME(Number, NumberdoesnotdetermineNickname,andNicknamedoesnotdetermineNumber.(Number,IseverydeterminantacandidateYES,inthiscasethereareNOdeterminants,butthismeetsthecriteria!ThereforeSTUDENT_NICKNAMEisinArethefieldsofthemultivalueddependencytheonlyfieldsinthisYES,ThereforeSTUDENT_NICKNAMEisinALLTABLESARENOWINBCNFANDSTEPTHREE:STATEFINALMODELPrimaryKeysareunderlined.ForeignKeysareitalicized.Non-PrimaryKeyCandidateKeys(AlternatePrimaryKeys)arestatedfollowingeachrelationasAlternateKeys[NOTE:Noneexist].ReferentialIntegrityConstraintsarestatedfollowingeachSTUDENT_3(Number,Name,Dorm,WHERESTUDENT.RoomTypemustexistinDORM_RATE.RoomTypeDORM_RATE(RoomType,DormCost)WHERESTUDENT_CLUB_MEMBERSHIP.Numbermustexistin STUDENT_CLUB_MEMBERSHIP.ClubmustexistinSTUDENT_CLUB_COST(Club,ClubCost)STUDENT_SIBLING(Number,Sibling)WHERESTUDENT_SIBLING.NumbermustexistinSTUDENT_3.NumberSTUDENT_NICKNAME(Number,Nickname)WHERE mbermustexistinMarciaAssumethatMarciakeepsatableofdataabouthercustomers.Considerjustthefollowingpartofthattable:CUSTOMER(Phone,Name,ExplaintheconditionsunderwhicheachofthefollowingarePhone→ Name, Name)→(Phone,LastName) Name)→Phone→→Phone Phone→→(Name,Phone→ Name,TRUEwhenphonenumbersare Name)→TRUEwheneachcombinationofphonenumberandNameis(Phone,LastName) TRUEwheneachcombinationofphonenumberandLastNameis Name)→TRUEwheneachcombinationofNameandLastNameisPhone→→TRUEwhenaphonenumberisassociatedwithmorethanonePhone TRUEwhenaphonenumberisassociatedwithmorethanonePhone→→(Name,TRUEwhenaphonenumberisassociatedwithmorethanonecombinationofNameandIsconditionA.7thesameasconditionsA.5andA.6?WhyorwhyNo,itisIfweweredealingwithregularfunctionaldependencies,theanswerwouldbeyes,condition7isthesameastheconditions5and6.ThisisbecauseofthefactthatifA→(B,C),thenA→BandA→Butwhendealingwithmultivalueddependencies,somethingislostiftheyareequivalent.Considerthefollowingtable:234-1234→→(“John”,“Joan”)[Name]234-1234→→(“Smith”,“Jones”)[LastName]234-1234→→(“JohnSmith”,“JoanJones”)[Name,Thefactisthatcondition7givesus“JohnSmith”and“JoanJones,”bothofwhicharerecognizableindividualswithavalidcombinationofNameandLastName.Butifweallowacombinationofconditions5and6wealsoget“JohnJones”and“JoanSmith,”whicharenonexistentpeople.Thus,condition7showstheequivalentofacompositeidentifierorcompositekey,andthisisNOTequivalenttotherandomsumofitsparts.ConsidertheCUSTOMER(Phone,Name,LastName)ORDER(OrderNumber,DateIn,DateOut,Phone)StateanappropriatereferentialintegrityORDER.PhonemustexistinConsidertheCUSTOMER(Phone,Name,ORDER(OrderNumber,DateIn,DateOut,Name,LastName)Whatdoesthefollowingreferentialintegrityconstraintmean?ORDER(Name,LastName)mustbeinCUSTOMER(Name,IsthisconstraintthesameasthesetofreferentialintegrityORDER(Name)mustbeinCUSTOMER(Name)ORDER(LastName)mustbeinCUSTOMER(LastName)ExplainwhyorwhyNo,theseconstraintsarenotequivalent.TheconstraintORDER(Name,LastName)mustbeinCUSTOMER(Name,requiresthatthecompositeforeignkeycombinationoftheNameandLastName(“JoeSmith”)mustexistasthecompositeprimarykeyinonerecordinCUSTOMER,whiletheconstraintsetORDER(Name)mustbeinCUSTOMER(Name)ORDER(LastName)mustbeinCUSTOMERdoesnotacknowledgetheexistenceofthecompositekeys,andwouldbemetiftheName(“Joe”)existedinonerecordinCUSTOMERandtheLastName(“Smith”)existedinanother,differentrecordinCUSTOMER.SinceeachORDERshouldbeassociatedwithonespecificCUSTOMER,weshouldusetheconstraintwiththecompositekeys:ORDER(Name,LastName)mustbeinCUSTOMER(Name,DoyoupreferthedesigninBorthedesigninC?ExplainyourThedesigninBispreferablegiventhatnamesarenotunique.WemayhavemorethanoneCUSTOMERnamed“JoeSmith”,buteachofthemshouldhaveadifferentphonenumber.Iftheydon’t,weneedtoaddasurrogatekey(CustomerNumberorCustomerID).Atthesametime,thisdesignislimitedbythefactthatPhonemustbeuniqueifitistofunctionastheprimarykey.Thismeansthatwecanonlyassociateoneinahouseholdwiththatphoneandthereforethcount.Again,addingasurrogatekey(CustomerNumberorCustomerID)wouldsolvetheproblem(andwouldbeamuchbetterdesign).TransformthefollowingtableintotwoormoretablesinBCNFand4NF.Indicatetheprimarykeys,candidatekeys,foreignkeys,andreferentialintegrityconstraints.Makeandstateassumptionsasnecessary.ORDER(CustomerNumber,Name,LastName,Phone,OrderNumber,DateIn,DateOut,ItemType,ty,ItemPrice,ExtendedPrice,SpecialInstructions)CustomerNumber→(Name,LastName),butnotCustomerNumber→→(Name,LastName)[NOTE:ThisanticipatesquestionFbelow]CustomerNumber→→Phone.Thismeansthattheremaybemorethanonephonenumberforeachcustomer.OneCUSTOMERhasmanyORDERS,buteachORDERisassociatedwithonlyoneOneORDERhasmanyItemTypes,buteachItemTypeoccursonlyonceinanyItempricedoesnotvaryfromordertoorder,soItemTypedeterminesSpecialInstructionsisassociatedwitheachitemtype,sincedifferentinstructionsmaybegivenfordifferentitems.Ordernumberisanumberassignedtotheordersthemselves,withoutassociationwithanyparticularcustomer.Thuswehavesuchnumbersas“123454”,123455”,etc,ratherthan“Customer101,Order1”,Customer101,Order2”,Customer102,Order1”,etc.ItemPricecanvarywithordersothatspecialpricingoffersarereflectedintheSTEPONE:LISTTHEMULTIVALUEDThereisonemultivaluedTosimplifytheothersteps,we’llbreakthisoutintoit’sowntableORDER_2(CustomerNumber,Name,LastName,OrderNumber,DateIn,DateOut,ItemType,ty,ItemPrice,ExtendedPrice,SpecialInstructions)CUSTOMER_PHONE(CustomerNumber,TheforeignkeywillbeCustomerNumber,butwestillhavenormalizationtoBCNFtodo,sowe’lladdthereferentialintegrityconstraintforthisrelationat oftheprocesswhenwehaveallthenormalizedrelations.STEPTWO:LISTTHEFUNCTIONALORDER_2(CustomerNumber,Name,LastName,OrderNumber,DateIn,DateOut,ItemType,ty,ItemPrice,ExtendedPrice,SpecialInstructions)Theotherattributeshavethefollowingfunctionaldependencies.Notethatthereareseveralthatseemto“overlap”–forexampleboththedeterminantsOrderNumberand(CustomerNumber,OrderNumber)determinemanyofthesameattributes.Thatisnormalforasetofattributesthatcontainmanythemes,andthese“overlaps”willbeeliminatedinthenormalizationprocess:OrderNumber,ItemType)→(CustomerNumber,Name,LastName,DateIn,DateOut,ty,ItemPrice,ExtendedPrice,SpecialInstructions)OrderNumber→(CustomerNumber, Name,LastName,DateIn,DateOut)CustomerNumber→(Name,LastName)Notethatyourstudentsmaylistsomeothervalid,butredundant,functionalthereareseveralthatseemto“overlap”thefunctionaldependenciesshownabout.Thesewillhavecompositedeterminants–forexampleboththedeterminantOrderNumbershownaboveandthedeterminant(CustomerNumber,OrderNumber)shownbelowdeterminemanyofthesameattributes.Thatisnormalforasetofattributesthatcontainmanythemes,andthese“overlaps”willbeeliminatedinthenormalizationprocess:CustomerNumber,OrderNumber)→(Name,LastName,DateIn,DateOut)STEPTHREE:LISTTHEINITIALCANDIDATEKEYSIseverydetermi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 智能家居物联网设备与平台建设方案
- 智能药品监管系统开发合同
- 企业IT外包服务协议
- 办公楼保洁服务合同
- 车联网智能科技产品销售协议书
- 农产品采购合同
- 房地产项目投资开发协议
- 餐饮业智能点餐与外卖管理系统开发
- 室内设计与装饰作业指导书
- 新能源汽车充电桩布局规划方案
- 部编版五年级语文上册第六单元教案(共6课时)
- 钻井与完井工程-第一章-钻井与完井工程概述
- (新版)工业机器人系统操作员(三级)职业鉴定理论考试题库(含答案)
- 食材配送服务方案(技术方案)
- 课件:《中华民族共同体概论》第一讲 中华民族共同体基础理论
- 2024-2025学年安徽省合肥市蜀山区数学四年级第一学期期末质量检测试题含解析
- 离婚协议书模板可打印(2024版)
- 2024国家开放大学电大专科《兽医基础》期末试题及答案试卷号2776
- 厂区保洁服务投标方案【2024版】技术方案
- 养老机构绩效考核及奖励制度
- 龙岩市2022-2023学年七年级上学期期末生物试题【带答案】
评论
0/150
提交评论