资源描述:
《数据库系统概念全套配套课件PPT ch2.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chapter2:IntrotoRelationalModelExampleofaRelationattributes(orcolumns)tuples(orrows)AttributeTypesThesetofallowedvaluesforeachattributeiscalledthedomainoftheattributeAttributevaluesare(normally)requiredtobeatomic;thatis,indivisibleThespecialvaluenullisamemberofeverydomainThenullvalueca
2、usescomplicationsinthedefinitionofmanyoperationsRelationSchemaandInstanceA1,A2,…,AnareattributesR=(A1,A2,…,An)isarelationschemaExample:instructor=(ID,name,dept_name,salary)Formally,givensetsD1,D2,….DnarelationrisasubsetofD1xD2x…xDnThus,arelationisasetofn-tuples(a1,a2,…,an)whereeachaiD
3、iThecurrentvalues(relationinstance)ofarelationarespecifiedbyatableAnelementtofrisatuple,representedbyarowinatableRelationsareUnorderedOrderoftuplesisirrelevant(tuplesmaybestoredinanarbitraryorder)Example:instructorrelationwithunorderedtuplesDatabaseAdatabaseconsistsofmultiplerelationsI
4、nformationaboutanenterpriseisbrokenupintopartsinstructorstudentadvisorBaddesign:univ(instructor-ID,name,dept_name,salary,student_Id,..)resultsinrepetitionofinformation(e.g.,twostudentshavethesameinstructor)theneedfornullvalues(e.g.,representanstudentwithnoadvisor)Normalizationtheory(C
5、hapter7)dealswithhowtodesign“good”relationalschemasKeysLetKRKisasuperkeyofRifvaluesforKaresufficienttoidentifyauniquetupleofeachpossiblerelationr(R)Example:{ID}and{ID,name}arebothsuperkeysofinstructor.SuperkeyKisacandidatekeyifKisminimalExample:{ID}isacandidatekeyforInstructorOneofth
6、ecandidatekeysisselectedtobetheprimarykey.whichone?Foreignkeyconstraint:ValueinonerelationmustappearinanotherReferencingrelationReferencedrelationSchemaDiagramforUniversityDatabaseRelationalQueryLanguagesProceduralvs.non-procedural,ordeclarative“Pure”languages:RelationalalgebraTuplerel
7、ationalcalculusDomainrelationalcalculusRelationaloperatorsSelectionoftuplesRelationrSelecttupleswithA=BandD>5σA=BandD>5(r)SelectionofColumns(Attributes)Relationr:SelectAandCProjectionΠA,C(r)Joiningtworelations–CartesianProductRelationsr,s:rxs:UnionoftworelationsRelationsr,s:rs:Setdi