




已阅读5页,还剩36页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1,RelationalAlgebra(关系代数),Operators(操作符)ExpressionTrees(表达式树),2,Whatisan“Algebra”(代数),Analgebraconsistsofoperatorsandatomicoperands:Operands-arevariableslikeXandconstantslike15.Operators-aretheusualarithmeticones:addition,subtraction,multiplicationanddivision.,X,+,15,Operands,Operator,3,WhatisRelationalAlgebra?,RelationalAlgebraisanotherexampleofanalgegra.Itsatomicoperandsare:1.Variablesthatstandforrelations2.Constants,whicharefiniterelations,4,OverviewofRelationalAlgebra,RelationalAlgebraisanotherexampleofanalgegra.Analgebrawhoseoperandsarerelationsorvariablesthatrepresentrelations.Operatorsaredesignedtodothemostcommonthingsthatweneedtodowithrelationsinadatabase.Theresultisanalgebrathatcanbeusedasaquerylanguageforrelations.,R,S,5,FourClassesofRelationalAlgebra(四类关系代数),Union,intersection,difference(并,交,叉)Usualsetoperations,butbothoperandsmusthavethesamerelationschema.Selection,Projection(选择,投影)Removepartsofarelation.CartesianProduct,join(笛卡尔积,连接)CombinethetuplesoftworelationsRenaming(重命名)Changetherelationschema,i.e.,thenamesofattributesorthenameoftherelationitself.,6,SetOperatorsonRelations(关系集合运算符),RUSunion,thesetofelementsthatareinRorSorboth.RSintersection,thesetofelementsthatareinbothRandS.RSdifference,thesetofelementsthatareinRbutnoinS.RequiredRandSmusthaveschemawithidenticalsetofattributes,andthetypes(domains)mustbethesame.Beforecalculation,thecolumnsofRandSmustbeordered.,7,8,Projection(投影),TheprojectionoperatorisusedtoproducefromarelationRanewrelationthathasonlysomeofRscolumns.L(R)LisalistofattributesfromtheschemaofR.TheresultisanewrelationthathasonlysomeofRscolumns.Eliminateduplicatetuples,ifany.,9,Example,title,year,length(Movies),Result,10,Example,RelationSells:barbeerpriceJoesBud2.50JoesMiller2.75SuesBud2.50SuesMiller3.00,11,Selection(选择),Theselectionoperator,appliedtoarelationR,producesanewrelationwithasubsetofRstuples.C(R)Cisacondition(asin“if”statements)thatreferstoattributesofR.TheresultisanewrelationwithasubsetofRstuplesthatsatisfyC.,12,Example,lentgh=100ANDstudioName=FOX(Movie),Result,13,Example,RelationSells:barbeerpriceJoesBud2.50JoesMiller2.75SuesBud2.50SuesMiller3.00,14,CartesianProduct(笛卡尔积),Orcross-product(交叉积),orjustproduct(积)RSPair(配对)eachtuplet1ofRwitheachtuplet2ofS.Result:anewrelationwithnewtuples,eachofthemconcatenation(连接)apairoft1t2,theattributesofRandSareinordered.Beware:attributeAofthesamenameinRandS:useR.AandS.A.,15,Example:R3:=R1R2,R1AB1234R2BC5678910,16,NaturalJoin(自然连接),RSPaironlythosetuplesfromRandSthatagreeinwhateverattributesarecommon(共同的)totheschemasofRandS.Eliminatingonecopyofeachpairofequatedattributes.,17,ABCa1b15a1b26a2b38a2b412,R,BEb13b27b310b32b52,S,AR.BCS.BEa1b15b27a1b15b310a1b26b27a1b26b310a2b38b310,RCES,AR.BCS.BEa1b15b13a1b26b27a2b38b310a2b38b32,等值连接,a1b153a1b267a2b3810a2b382,自然连接,RR.B=S.BS,RS,Example:NaturalJoin,18,Example:NaturalJoin,SellsbarbeerpriceBarsbaraddrJoesBud2.50JoesMapleSt.JoesMiller2.75SuesRiverRd.SuesBud2.50SuesCoors3.00BarInfo:=SellsBarsNote:BhasbecomeBars.bartomakethenaturaljoin“work.”,19,Example:NaturalJoin,(a)RelationU,(b)RelationV,(c)ResultUV,20,Theta-Join(连接),RCSTaketheproductRS.ThenapplyCtotheresult.,21,ABCa1b15a1b26a2b38a2b412,R,BEb13b27b310b32b52,S,AR.BCS.BEa1b15b27a1b15b310a1b26b27a1b26b310a2b38b310,RC0),那么RS是一个(r-s)元的元组的集合,(RS)是满足下列条件的最大关系:其中每个元组t与S中每个元组u组成的新元组必在关系R中.具体过程:(1)T=r-s(R)(2)W=(TS)-R(3)V=r-s(W)(4)RS=T-V,33,例:RS,RSRS,34,Precedenceofrelationaloperators:(关系运算符的优先级),Unary(一元的)operators-select,project-havehighestprecedence,bindfirst.Thencomeproductsandjoins.Thenintersection.Finally,unionandsetdifferencebindlast.Butyoucanalwaysinsertparenthesestoforcetheorderyoudesire.,35,例:学生课程数据库,包括Student,Course,SC三个关系,SnoSnameSsexSageSdept95001李勇男20CS95002刘晨女19IS95003王敏女18MA95004张立男19IS,Student,CnoCnameCpqoCcredit1数据库542数学2信息系统144操作系统635数据结构746数据处理27Pascal语言64,Course,SnoCnoGrade9500119295001285950013889500229095002380,SC,36,Sname,Sdept(Student),Sdept=IS(Student),Sno(Cno=1(SC),Sno(Cno=1orCno=3(SC),Student(Sno,Sname,Ssex,Sage,Sdept)Course(Cno,Cname,Cpqo,Ccredit)SC(Sno,Cno,Grade),37,教学数据库,教师关系T(T#,TNAME,TITLE)课程关系C(C#,CNAME,T#)学生关系S(S#,SNAME,AGE,SEX)选课关系SC(S#,C#,SCORE),1.检索学习课程号为C2课程的学生学号与成绩。2.检索学习课程号为C2课程的学生学号与姓名。3.检索至少选修LIU老师所授课程中一门课程的学生学号与姓名4.检索选修课程号为C2或C4课程的学生学号。5.检索选修课程号为C2和C4课程的学生学号。6.检索不学C2课程的学生姓名与年龄。,38,Example(1):,Teachingdatabaseasfollows:Writethefollowingqueriesinrelationalalgebra.(写关系代数表达式),1.检索学习课程号为C2课程的学生学号与成绩。S#,SCORE(C#=C2(SC)2.检索学习课程号为C2课程的学生学号与姓名。S#,SNAME(C#=C2(SC)S)3.检索至少选修LIU老师所授课程中一门课程的学生学号与姓名S#,SNAME(TNAME=LIU(T)CSCS),1,3(2=C2(SC),39,Example(2):,4.检索选修课程号为C2或C4课程的学生学号。S#(C#=C2ORC#=C4(SC)5.检索选修课程号为C2和C4课程的学生学号。S#(C#=C2(SC)S#(C#=C4(SC)6.检索不学C2课程的学生姓名与年龄。SNAME,AGE(S)-SNAME,AGE(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 航空航天复合材料 课件知识点2 预浸料制备工艺
- 航空航天复合材料 课件第1章 知识点3 增强体概述
- 济源历年试题及答案
- 暗股协议书模版
- 物业维修监理工作总结
- 沥青混合料摊铺机-电力水利-工程科技-专业资料
- 2025年 广西北海供电局项目资料员招聘考试试卷附答案
- 新生开学思想培训
- 2025年中国皮肤爽肤水行业市场全景分析及前景机遇研判报告
- 企业介绍培训
- 08S305-小型潜水泵选用及安装图集
- 医院手术患者术前术后访视记录单
- 三世演禽命理秘书讲课教案
- 门诊医院感染管理质量检查标准
- 论文交流汇报课件
- 津山铁路立交桥试转体施工准备汇报材料(47页)
- 美的集团公司分权手册
- 建筑行业安徽某抽水蓄能电站人工砂石加工系统工程施工技术标书
- 通风与空调工程施工工艺流程图
- 协议回款承诺书
- 贺州学院专业实习鉴定表
评论
0/150
提交评论