资源描述:
《第四讲 第2章 关系数据库(关系代数2)ppt课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、数据库技术及应用TechnologiesandApplicationsofDatabases华中科技大学水电与数字化工程学院第二章关系数据库RelationalDatabasesLecture4关系代数RelationalAlgebraLearningObjectivesEvolutionandimportanceofrelationalmodelTermsinrelationalmodelliketuple,domain,cardinality,anddegreeofarelationOperationsinrelatio
2、nalalgebraRelationalAlgebraProcedurallanguageSixbasicoperatorsselect:project:union:setdifference:–Cartesianproduct:xrename:Theoperatorstakeoneortworelationsasinputsandproduceanewrelationasaresult.SelectOperation–ExampleRelationrA=B^D>5(r)SelectOperationNotatio
3、n:p(r)piscalledtheselectionpredicateDefinedas:p(r)={t
4、trandp(t)}Wherepisaformulainpropositionalcalculusconsistingoftermsconnectedby:(and),(or),(not)Eachtermisoneof:oporwhereopisoneof:=,,>,.<.Exampleofselection:dept_name=“P
5、hysics”(instructor)ProjectOperation–ExampleRelationr:A,C(r)ProjectOperationNotation:whereA1,A2areattributenamesandrisarelationname.TheresultisdefinedastherelationofkcolumnsobtainedbyerasingthecolumnsthatarenotlistedDuplicaterowsremovedfromresult,sincerelationsares
6、etsExample:Toeliminatethedept_nameattributeofinstructorID,name,salary(instructor)UnionOperation–ExampleRelationsr,s:rs:UnionOperationNotation:rsDefinedas:rs={t
7、trorts}Forrstobevalid.1.r,smusthavethesamearity(samenumberofattributes)2.Theattributedomainsmustbe
8、compatible(example:2ndcolumnofrdealswiththesametypeofvaluesasdoesthe2ndcolumnofs)Example:tofindallcoursestaughtintheFall2009semester,orintheSpring2010semester,orinbothcourse_id(semester=“Fall”Λyear=2009(section))course_id(semester=“Spring”Λyear=2010(section)
9、)SetdifferenceoftworelationsRelationsr,s:r–s:SetDifferenceOperationNotationr–sDefinedas:r–s={t
10、trandts}Setdifferencesmustbetakenbetweencompatiblerelations.randsmusthavethesamearityattributedomainsofrandsmustbecompatibleExample:tofindallcoursestaughtintheFall2009s
11、emester,butnotintheSpring2010semestercourse_id(semester=“Fall”Λyear=2009(section))−course_id(semester=“Spring”Λyear=2010(section))Cartesian-