



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、DataBase Chapter Two OutlineThe set of allowed values for each attribute is called the domain of the attributer(R) is a relation on the relation schema R Example:customer (Customer_schema)About Key:K is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relati
2、on r(R) K is a candidate key if K is minimal (最小超码)Primary Key : 被数据库设计者选中的用来在同一关系中区分不同元组的候选码。Relational AlgebraProcedural languageSix basic operatorsselect: s project: union: set difference: Cartesian product: xrename: r The operators take one or two relations as inputs and produce a new relation a
3、s a result.Select OperationNotation: s p(r)p is called the selection predicate Defined as: sp(r) = t | t r and p(t)Where p is a formula in propositional calculus consisting of terms connected by : (and), (or), (not)Each term is one of:op or where op is one of: =, , , . . Project OperationNotation:wh
4、ere A1, A2 are attribute names and r is a relation name.Union OperationNotation: r sDefined as: r s = t | t r or t sFor r s to be valid.1. r, s must have the same arity (same number of attributes)2. The attribute domains must be compatible (example: 2nd column of r deals with the same type of values
5、 as does the 2nd column of s)Set Difference OperationNotation r sDefined as: r s = t | t r and t sSet differences must be taken between compatible relations.r and s must have the same arity attribute domains of r and s must be compatible Cartesian-Product OperationNotation r x s Defined as:r x s = t
6、 q | t r and q sAssume that attributes of r(R) and s(S) are disjoint. (That is, R S = ).If attributes of r(R) and s(S) are not disjoint, then renaming must be used.Rename OperationAllows us to name, and therefore to refer to, the results of relational-algebra expressions.Allows us to refer to a rela
7、tion by more than one name.Example: r x (E)returns the expression E under the name X If a relational-algebra expression E has arity n, then returns the result of expression E under the name X, and with theattributes renamed to A1 , A2 , ., An .Additional OperationsSet-Intersection OperationNotation:
8、 r s Defined as:r s = t | t r and t s Assume: r, s have the same arity attributes of r and s are compatibleNote: r s = r (r s)Natural-Join OperationNotation: rsLet r and s be relations on schemas R and S respectively. Then, r s is a relation on schema R S obtained as follows:Consider each pair of tu
9、ples tr from r and ts from s. If tr and ts have the same value on each of the attributes in R S, add a tuple t to the result, wheret has the same value as tr on r t has the same value as ts on s q -Join Operationrqs= s q (r x s)Division OperationNotation: Suited to queries that include the phrase “f
10、or all”.Let r and s be relations on schemas R and S respectively whereR = (A1, , Am , B1, , Bn )S = (B1, , Bn)The result of r s is a relation on schemaR S = (A1, , Am)r s = t | t R-S (r) u s ( tu r ) Where tu means the concatenation of tuples t and u to produce a single tuple r s = R-S (r ) R-S ( (
11、R-S (r ) x s ) R-S,S(r )Assignment OperationThe assignment operation () provides a convenient way to express complex queries. Write query as a sequential program consisting ofa series of assignments followed by an expression whose value is displayed as a result of the query.Assignment must always be
12、 made to a temporary relation variable.Example: Write r s as temp1 R-S (r ) temp2 R-S (temp1 x s ) R-S,S (r )result temp1 temp2 The result to the right of the is assigned to the relation variable on the left of the .May use variable in subsequent expressions.Extended Relational-Algebra-OperationsGen
13、eralized Projection 允许投影使用算数运算跟重命名。Extends the projection operation by allowing arithmetic functions to be used in the projection list.E is any relational-algebra expressionEach of F1, F2, , Fn are are arithmetic expressions involving constants and attributes in the schema of E.Given relation credit
14、_info(customer_name, limit, credit_balance), find how much more each person can spend: customer_name, limit credit_balance (credit_info) Also, we can apply rename operation:customer_name, limit credit_balance as credit_availble (credit_info) Aggregate Functions and Operations 允许使用列函数,并且分组。Aggregatio
15、n function takes a collection of values and returns a single value as a result.avg: average value min: minimum value max: maximum value sum: sum of values count: number of valuesAggregate operation in relational algebra E is any relational-algebra expressionG1, G2 , Gn is a list of attributes on whi
16、ch to group (can be empty)Each Fi is an aggregate function Each Ai is an attribute nameThe schema of result is (G1, G2 , Gn , a1, a2 , am ).where ai is the result of applying the aggregate function Fi on the multiset of values for attribute Ai in the groupOuter JoinAn extension of the join operation
17、 that avoids loss of information.Computes the join and then adds tuples form one relation that does not match tuples in the other relation to the result of the join. Uses null values:null signifies that the value is unknown or does not exist All comparisons involving null are (roughly speaking) fals
18、e by definition.We shall study precise meaning of comparisons with nulls laterThe result of any arithmetic expression involving null is null.Modification of the DatabaseDeletionCan delete only whole tuples; cannot delete values on only particular attributesA deletion is expressed in relational algebra by:r r E where r is a relation and E is a relational algebra query. InsertionTo insert data into a relation, we either:specify a tuple to be insertedwrite a query whose result is a set of tu
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 流动科技馆观后感范文
- 海洋增材制造产业发展概述
- 海洋航道建设与维护
- 老年护理介绍课件教学
- 拆除工程合同履约及终止合同
- 夫妻离婚后彩礼返还及财产分割协议
- 材料物理晶体物理物理物理物理物理物理电化学合同
- 边疆古代民族舞蹈考古合同
- 餐饮行业拆伙退伙协议书(财务清算)
- 牛场租赁与绿色养殖技术支持合同
- DIP支付下的病案首页填写
- 《不锈钢培训知识》课件
- 2024秋季期末全体教师大会上初中校长讲话:春华秋实又一载接续奋斗开新篇
- 2025年浙江杭州市西湖区专职社区招聘85人历年高频重点提升(共500题)附带答案详解
- 《AIB审核基础》课件
- KCA试题库完整版
- 国家电网安规线路培训
- 围手术期管理制度及流程
- 【高分复习笔记】吴于廑《世界史·近代史编(上下卷)》(第2版)笔记和典型题(含考研真题)详解
- 七年级下册古诗词对比阅读训练-2025年中考语文复习之古代诗歌阅读
- 配合、协调、服务方案
评论
0/150
提交评论