



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2019-2025年军队文职人员招聘之军队文职管理学与服务自我检测试卷A卷附答案
- 2025年全国硕士研究生考试《政治》模拟试卷一
- H2H行业虚拟现实技术研究与应用方案
- 智慧之书少儿版读后感
- 火锅店合伙人协议书
- 小学生作文竞赛感悟分享
- 河北省张家口市万全区2024-2025学年七年级上学期期末生物学试题(含答案)
- 墩、台身和盖梁工程现场质量检验报告单(四)
- 农村社区土地流转管理服务协议
- 公司股东合作协议及其权利分配计划
- 劳务派遣劳务外包项目方案投标文件(技术方案)
- 2025年安全员C证(专职安全员)考试题库
- 地理-天一大联考2025届高三四省联考(陕晋青宁)试题和解析
- 2025年广州市公安局招考聘用交通辅警200人高频重点模拟试卷提升(共500题附带答案详解)
- 贵州省贵阳市2024-2025学年九年级上学期期末语文试题(含答案)
- 2025年江苏海事职业技术学院高职单招职业适应性测试近5年常考版参考题库含答案解析
- 计件工资计算表格模板
- 两癌防治知识培训
- 《moldflow学习资料》课件
- 2025中国移动安徽分公司春季社会招聘高频重点提升(共500题)附带答案详解
- 2024年吉安职业技术学院单招职业技能测试题库附答案
评论
0/150
提交评论