数据库课件总结:Database Chapter Three Outline

上传人:努力****83 文档编号:160873330 上传时间:2022-10-11 格式:DOCX 页数:7 大小:1.06MB
收藏 版权申诉 举报 下载
数据库课件总结:Database Chapter Three Outline_第1页
第1页 / 共7页
数据库课件总结:Database Chapter Three Outline_第2页
第2页 / 共7页
数据库课件总结:Database Chapter Three Outline_第3页
第3页 / 共7页
资源描述:

《数据库课件总结:Database Chapter Three Outline》由会员分享,可在线阅读,更多相关《数据库课件总结:Database Chapter Three Outline(7页珍藏版)》请在装配图网上搜索。

1、Database Chapter Three OutlineSQLSQL names are case insensitive 不区分大小写Data Definition Language Create Table ConstructAn SQL relation is defined using the create table command:create table r (A1 D1, A2 D2, ., An Dn,(integrity-constraint1),.,(integrity-constraintk)r is the name of the relationeach Ai

2、is an attribute name in the schema of relation rDi is the data type of values in the domain of attribute Ai Integrity Constraints in Create Tablenot nullprimary key (A1, ., An ) Example: Declare branch_name as the primary key for branch and ensure that the values of assets are non-negative. create t

3、able branch (branch_namechar(15), branch_citychar(30), assetsinteger, primary key (branch_name), check(assets=0)PRIMARY KEY - FOREIGN KEY - CHECKDrop and Alter Table Constructsalter table r add A D 添加属性 alter table r drop A 删除属性Drop table r 删除表Basic Query StructureA typical SQL query has the form:se

4、lect A1, A2, ., Anfrom r1, r2, ., rmwhere PAi represents an attributeRi represents a relationP is a predicate.This query is equivalent to the relational algebra expression.The result of an SQL query is a relation.The meaning of select is different fromThe select clause can contain arithmetic express

5、ions involving the operation, +, , *, and /, and operating on constants or attributes of tuples.DISTINCT - FROM - WHERE - GROUB BY - HAVING - ORDER BY. ASC DESCThe Rename Operation old-name as new-nameString OperationsThe operator “like” uses patterns that are described using two special characters:

6、percent (%). The % character matches any substring.underscore (_). The _ character matches any character. concatenation (using “|”) converting from upper to lower case (and vice versa) (upper, lower) finding string length, extracting substrings, etc.Set Operations(select customer_name from depositor

7、)union(select customer_name from borrower) Intersect、except;自动去除重复。若要全部则: UNION ALL 、 INTERSECT ALL 、 EXCEPT ALL;Aggregate Functionsavg: average value min: minimum value max: maximum value sum: sum of valuescount: number of valuesGroup ByHaving ClauseAll aggregate operations except count(*) ignore t

8、uples with null values on the aggregated attributes.Nested SubqueriesA subquery is a select-from-where expression that is nested within another query (appear in where clause or having by clause). Cant use order by in subquery set membership: in and not inSet Comparison SOME大于子查询结果中的某个值 ALL大于子查询结果中的所

9、有值 SOME 小于子查询结果中的某个值 = SOME 大于等于子查询结果中的某个值 = ALL大于等于子查询结果中的所有值= SOME 小于等于子查询结果中的某个值 = ALL小于等于子查询结果中的所有值= SOME 等于子查询结果中的某个值 =ALL等于子查询结果中的所有值(通常没有实际意义)!=(或) SOME 不等于子查询结果中的某个值!=(或)ALL不等于子查询结果中的任何一个值 (= some) in However, ( some) not in ( all) not in However, (= all) inexists r r 如果子查询不为空,则返回true;not ex

10、ists r r = Relevant Nested Subqueries NOT EXIST(B EXCEPT A) 表示关系A包含关系B。The unique construct tests whether a subquery has any duplicate tuples in its result. (专门用来处理“只有一个”、“有两个或者两个以上的”)Derived RelationsSQL allows a subquery expression to be used in the from clauseFind the average account balance of t

11、hose branches where the average account balance is greater than $1200.select branch_name, avg_balancefrom (select branch_name, avg (balance) from account group by branch_name ) as branch_avg ( branch_name, avg_balance )where avg_balance 1200Note that we do not need to use the having clause, since we

12、 compute the temporary (view) relation branch_avg in the from clause, and the attributes of branch_avg can be used directly in the where clause.With ClauseThe with clause provides a way of defining a temporary view whose definition is available only to the query in which the with clause occurs. View

13、s (只要没有更新操作,视图可以出现在关系名出现的任何地方)A view provides a mechanism to hide certain data from the view of certain users. create view v as A view definition causes the saving of an expression; the expression is substituted into queries using the view.Views Defined Using Other ViewsA view relation v1 is said to

14、 depend directly on a view relation v2 if v2 is used in the expression defining v1 A view relation v1 is said to depend on view relation v2 if either v1 depends directly to v2 or there is a path of dependencies from v1 to v2 A view relation v is said to be recursive if it depends on itself.View Expa

15、nsionView expansion of an expression repeats the following replacement step:repeatFind any view relation vi in e1Replace the view relation vi by the expression defining vi until no more view relations are present in e1 As long as the view definitions are not recursive, this loop will terminateModifi

16、cation of the Database Deletion Delete from r where PModification of the Database InsertionInsert into r(A1,A2,An) values(v1,v2, ,vn)Modification of the Database UpdatesUPDATE r SET A1=v1,Ai=vi WHERE P update account set balance = case when balance = 10000 then balance *1.05 else balance * 1.06 endUpdate of a ViewMost SQL implementations allow updates only on simple views (without aggregates) defined on a single relation

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!