资源描述:
《数据库系统概念全套配套课件PPT ch6.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chapter6:FormalRelationalQueryLanguagesChapter6:FormalRelationalQueryLanguagesRelationalAlgebraTupleRelationalCalculusDomainRelationalCalculusRelationalAlgebraProcedurallanguageSixbasicoperatorsselect:project:union:setdifference:–Cartesianproduct:xrename:Theoperatorstakeo
2、neortworelationsasinputsandproduceanewrelationasaresult.SelectOperation–ExampleRelationrA=B^D>5(r)SelectOperationNotation:p(r)piscalledtheselectionpredicateDefinedas:p(r)={t
3、trandp(t)}Wherepisaformulainpropositionalcalculusconsistingoftermsconnectedby:(and),(or),(not)
4、Eachtermisoneof:oporwhereopisoneof:=,,>,.<.Exampleofselection:dept_name=“Physics”(instructor)ProjectOperation–ExampleRelationr:A,C(r)ProjectOperationNotation:whereA1,A2areattributenamesandrisarelationname.Theresultisdefinedastherelationofk
5、columnsobtainedbyerasingthecolumnsthatarenotlistedDuplicaterowsremovedfromresult,sincerelationsaresetsExample:Toeliminatethedept_nameattributeofinstructorID,name,salary(instructor)UnionOperation–ExampleRelationsr,s:rs:UnionOperationNotation:rsDefinedas:rs={t
6、trorts}Forr
7、stobevalid.1.r,smusthavethesamearity(samenumberofattributes)2.Theattributedomainsmustbecompatible(example:2ndcolumnofrdealswiththesametypeofvaluesasdoesthe2ndcolumnofs)Example:tofindallcoursestaughtintheFall2009semester,orintheSpring2010semester,orinbothcourse_id(semester
8、=“Fall”Λyear=2009(section))course_id(semester=“Spring”Λyear=2010(section))SetdifferenceoftworelationsRelationsr,s:r–s:SetDifferenceOperationNotationr–sDefinedas:r–s={t
9、trandts}Setdifferencesmustbetakenbetweencompatiblerelations.randsmusthavethesamearityattributedomainsof
10、randsmustbecompatibleExample:tofindallcoursestaughtintheFall2009semester,butnotintheSpring2010semestercourse_id(semester=“Fall”Λyear=2009(section))−course_id(semester=“Spring”Λyear=2010(section))Cartesian-ProductOperation–ExampleRelationsr,s:rxs:Cartesian-ProductOperation
11、NotationrxsDefinedas:rxs={tq
12、trandqs}Assumethatattributesofr(R)and