数据库原理英文课件chapter4-RelationalAlgebra.ppt

上传人:小飞机 文档编号:5985529 上传时间:2023-09-11 格式:PPT 页数:27 大小:227.63KB
返回 下载 相关 举报
数据库原理英文课件chapter4-RelationalAlgebra.ppt_第1页
第1页 / 共27页
数据库原理英文课件chapter4-RelationalAlgebra.ppt_第2页
第2页 / 共27页
数据库原理英文课件chapter4-RelationalAlgebra.ppt_第3页
第3页 / 共27页
数据库原理英文课件chapter4-RelationalAlgebra.ppt_第4页
第4页 / 共27页
数据库原理英文课件chapter4-RelationalAlgebra.ppt_第5页
第5页 / 共27页
点击查看更多>>
资源描述

《数据库原理英文课件chapter4-RelationalAlgebra.ppt》由会员分享,可在线阅读,更多相关《数据库原理英文课件chapter4-RelationalAlgebra.ppt(27页珍藏版)》请在三一办公上搜索。

1、1,Database Principles,2,Chapter 4 Relational Algebra,OperatorsExpression Trees,3,What is an“Algebra”,Mathematical system consisting of:Operands-variables or values from which new values can be constructed.Operators-symbols denoting procedures that construct new values from given values.,4,What is Re

2、lational Algebra?,An algebra whose operands are relations or variables that represent relations.Operators are designed to do the most common things that we need to do with relations in a database.The result is an algebra that can be used as a query language for relations.,5,What we will learn,Core(o

3、r traditionally)relational algebra,6,Core Relational Algebra,Union,intersection,and difference.Usual set operations,but require both operands have the same relation schema.Selection:picking certain rows.Projection:picking certain columns.Products and joins:compositions of relations.,7,Operators,8,Se

4、t Operators,R U S:union,the set of elements that are in R or S or both.R S:intersection,the set of elements that are in both R and S.R-S:difference,the set of elements that are in R but no in S.RequiredR and S must have schema with identical set of attributes,andBefore calculation,the columns of R a

5、nd S must be ordered.,9,10,Projection,L(R)L is a list of attributes from the schema of R.The result is a new relation that has only some of Rs columns.Eliminate duplicate tuples,if any.Example title,year,length(Movie),11,Selection,C(R)C is a condition(as in“if”statements)that refers to attributes of

6、 R.The result is a new relation with a subset of Rs tuples that satisfy C.Example,lentgh=100 AND studioName=Fox(Movie),12,Cartesian Product,or just productR SPair each tuple t1 of R with each tuple t2 of S.Result:a new relation with new tuples,each of them concatenation a pair of t1t2,the attributes

7、 of R and S are in ordered.But beware attribute A of the same name in R and S:use R.A and S.A.,13,RS,A B C A B C a1 b1 c1 a1 b2 c2 a1 b1 c1 a1 b3 c2 a1 b1 c1 a2 b2 c1 a1 b2 c2 a1 b2 c2 a1 b2 c2 a1 b3 c2 a1 b2 c2 a2 b2 c1 a2 b2 c1 a1 b2 c2 a2 b2 c1 a1 b3 c2 a2 b2 c1 a2 b2 c1,14,Natural Join,A frequen

8、t type of join connects two relations by:Equating attributes of the same name,andProjecting out one copy of each pair of equated attributes.Called natural join.Denoted:R1 R2,15,Theta-Join,R C STake the product R x S.Then apply C to the result.C can be any boolean-valued condition.Historic versions o

9、f this operator allowed only A theta B,where theta was=,etc.,16,A B Ca1 b1 5a1 b2 6a2 b3 8a2 b4 12,R,B E b1 3 b2 7 b3 10 b3 2 b5 2,S,A R.B C S.B E a1 b1 5 b2 7 a1 b1 5 b3 10 a1 b2 6 b2 7 a1 b2 6 b3 10 a2 b3 8 b3 10,R CE S,A R.B C S.B E a1 b1 5 b1 3 a1 b2 6 b2 7 a2 b3 8 b3 10 a2 b3 8 b3 2,等值连接,a1 b1

10、5 3 a1 b2 6 7 a2 b3 8 10 a2 b3 8 2,自然连接,R R.B=S.B S,R S,17,Outerjoin,Suppose we join R C S.A tuple of R that has no tuple of S with which it joins is said to be dangling.Similarly for a tuple of S.Outerjoin preserves dangling tuples by padding them with a special NULL symbol in the result.,18,Exampl

11、e:Outerjoin,R=ABS=BC12234567(1,2)joins with(2,3),but the other two tuplesare dangling.,19,Dependent and Independent Operations,20,Combining Operations to Form Query,Algebras allow us to express sequences of operations in a natural way.Example:in arithmetic-(x+4)*(y-3).Relational algebra allows the s

12、ame.For example,title,year(lentgh=100(Movie)studioName=Fox(Movie),21,Expressions,Precedence of relational operators:Unary operators-select,project-have highest precedence,bind first.Then come products and joins.Then intersection.Finally,union and set difference bind last.But you can always insert pa

13、rentheses to force the order you desire.,22,Expression Trees,Leaves are operands-either variables standing for relations or particular,constant relations.Interior nodes are operators,applied to their child or children.,23,For example:,24,例:学生课程数据库,包括Student,Course,SC三个关系,Sno Sname Ssex Sage Sdept950

14、01 李勇 男 20 CS95002 刘晨 女 19 IS95003 王敏 女 18 MA95004 张立 男 19 IS,Student,Cno Cname Cpqo Ccredit1 数据库 5 42数学 2信息系统 1 44 操作系统 6 35 数据结构 7 4 6 数据处理 27 Pascal语言 6 4,Course,Sno Cno Grade95001 1 9295001 2 8595001 3 8895002 2 9095002 3 80,SC,25,Sname,Sdept(Student),Sdept=IS(Student),Sno(Cno=1(SC),Sno(Cno=1 or

15、 Cno=3(SC),26,Reading Guide,Required:4.1Recommended:数据库系统概论第二章中的关系代数,27,练习,图书馆管理数据库读者(读者编号,姓名,单位)图书(书号,书名,作者,出版社,单价,类型)借阅记录(读者编号,书号,借阅日期,应还日期)还书记录(读者编号,书号,归还日期)用关系代数描述以下查询要求查询“人民邮电出版社”出版的所有图书的相关信息查询单价在15元以上的书名和作者查询8号读者2003年3月10日所借图书的相关信息查询超期归还图书的读者姓名和单位查询借阅过天龙八部的读者的信息查询借阅过“金庸”所有著作的读者的姓名查询没有借阅过任何图书的读者的姓名,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号