• 1.88 MB
  • 2022-04-29 14:33:33 发布

数据库系统概念全套配套课件PPT ch2.ppt

  • 30页
  • 当前文档由用户上传发布,收益归属用户
  1. 1、本文档共5页,可阅读全部内容。
  2. 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
  3. 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
  4. 文档侵权举报电话:19940600175。
'Chapter2:IntrotoRelationalModel ExampleofaRelationattributes(orcolumns)tuples(orrows) AttributeTypesThesetofallowedvaluesforeachattributeiscalledthedomainoftheattributeAttributevaluesare(normally)requiredtobeatomic;thatis,indivisibleThespecialvaluenullisamemberofeverydomainThenullvaluecausescomplicationsinthedefinitionofmanyoperations RelationSchemaandInstanceA1,A2,…,AnareattributesR=(A1,A2,…,An)isarelationschemaExample:instructor=(ID,name,dept_name,salary)Formally,givensetsD1,D2,….DnarelationrisasubsetofD1xD2x…xDnThus,arelationisasetofn-tuples(a1,a2,…,an)whereeachaiDiThecurrentvalues(relationinstance)ofarelationarespecifiedbyatableAnelementtofrisatuple,representedbyarowinatable RelationsareUnorderedOrderoftuplesisirrelevant(tuplesmaybestoredinanarbitraryorder)Example:instructorrelationwithunorderedtuples DatabaseAdatabaseconsistsofmultiplerelationsInformationaboutanenterpriseisbrokenupintopartsinstructorstudentadvisorBaddesign:univ(instructor-ID,name,dept_name,salary,student_Id,..) resultsinrepetitionofinformation(e.g.,twostudentshavethesameinstructor)theneedfornullvalues(e.g.,representanstudentwithnoadvisor)Normalizationtheory(Chapter7)dealswithhowtodesign“good”relationalschemas KeysLetKRKisasuperkeyofRifvaluesforKaresufficienttoidentifyauniquetupleofeachpossiblerelationr(R)Example:{ID}and{ID,name}arebothsuperkeysofinstructor.SuperkeyKisacandidatekeyifKisminimal Example:{ID}isacandidatekeyforInstructorOneofthecandidatekeysisselectedtobetheprimarykey.whichone?Foreignkeyconstraint:ValueinonerelationmustappearinanotherReferencingrelationReferencedrelation SchemaDiagramforUniversityDatabase RelationalQueryLanguagesProceduralvs.non-procedural,ordeclarative“Pure”languages:RelationalalgebraTuplerelationalcalculusDomainrelationalcalculusRelationaloperators SelectionoftuplesRelationrSelecttupleswithA=BandD>5σA=BandD>5(r) SelectionofColumns(Attributes)Relationr:SelectAandCProjectionΠA,C(r) Joiningtworelations–CartesianProductRelationsr,s:rxs: UnionoftworelationsRelationsr,s:rs: SetdifferenceoftworelationsRelationsr,s:r–s: SetIntersectionoftworelationsRelationr,s:rs Joiningtworelations–NaturalJoinLetrandsberelationsonschemasRandSrespectively. Then,the“naturaljoin”ofrelationsRandSisarelationonschemaRSobtainedasfollows:Considereachpairoftuplestrfromrandtsfroms.IftrandtshavethesamevalueoneachoftheattributesinRS,addatuplettotheresult,wherethasthesamevalueastronrthasthesamevalueastsons NaturalJoinExampleRelationsr,s:NaturalJoinrs Figurein-2.1 EndofChapter2 Figure2.01 Figure2.02 Figure2.03 Figure2.04 Figure2.05 Figure2.06 Figure2.07 Figure2.10 Figure2.11 Figure2.12 Figure2.13'