海南大学:《数据库原理及应用》课程PPT教学课件(英文版)Chapter 4 SQL

Chapter 4: SQL Background Basic Structure Set Operations Aggregate Functions Null values Nested Subqueries Derived relations Views Modification of the database Joined relations Data Definition Language Embedded SQL ODBC and JDBC 标 Database System Concepts 4.1 @Silberschatz, Korth and Sudarshan
Database System Concepts 4.1 ©Silberschatz, Korth and Sudarshan Chapter 4: SQL Background Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Joined Relations Data Definition Language Embedded SQL, ODBC and JDBC

Background In 1986, ANSI and iso published an SQL standard, called SQL-86 In 1989, ANSI published an extended standard for SQL, called SQL-89 SQL-92 and sQL-1999(SQL3) The sQL language has several parts: Data-definition language(DDL) Interactive data-manipulation language(DML) View definition Transaction control Embedded SQL and dynamic SQL Integrity Database System Authorization OSilberschatz. Korth and Sudarshan
Database System Concepts 4.2 ©Silberschatz, Korth and Sudarshan Background In 1986, ANSI and ISO published an SQL standard, called SQL-86 In 1989, ANSI published an extended standard for SQL, called SQL-89 SQL-92 and SQL-1999(SQL3) The SQL language has several parts: Data-definition language (DDL) Interactive data-manipulation language (DML) View definition Transaction control Embedded SQL and dynamic SQL Integrity Authorization

Basic structure A typical SQL query has the form: select a1,A2y…,A from r1,fr2y…;,rm where P Ais represent attributes ris represent relations P is a predicate. This query is equivalent to the relational algebra expression. IA,A2,….An(p(1xF2x…xrm) The result of an SQL query is a relation Database System Concepts 4.3 OSilberschatz. Korth and Sudarshan
Database System Concepts 4.3 ©Silberschatz, Korth and Sudarshan Basic Structure A typical SQL query has the form: select A1 , A2 , ..., An from r1 , r2 , ..., rm where P Ais represent attributes ris represent relations P is a predicate. This query is equivalent to the relational algebra expression. A1, A2, ..., An(P (r1 x r2 x ... x rm)) The result of an SQL query is a relation

The select Clause The select clause list the attributes desired in the result of a query corresponds to the projection operation of the relational algebra E.g. find the names of all branches in the loan relation select branch-name from loan In the"pure"relational algebra syntax, the query would be. Lbranch-name (loan) 标 Database System Concepts OSilberschatz. Korth and Sudarshan
Database System Concepts 4.4 ©Silberschatz, Korth and Sudarshan The select Clause The select clause list the attributes desired in the result of a query corresponds to the projection operation of the relational algebra E.g. find the names of all branches in the loan relation select branch-name from loan In the “pure” relational algebra syntax, the query would be: branch-name(loan)

The select Clause(Cont) SQL allows duplicates in relations as well as in query results. To force the elimination of duplicates, insert the keyword distinct after select. Find the names of all branches in the loan relations, and remove duplicates select distinct branch-name from loan The keyword all specifies that duplicates not be removed select all branch-name from loan Database System Concepts 4.5 @Silberschatz, Korth and Sudarshan
Database System Concepts 4.5 ©Silberschatz, Korth and Sudarshan The select Clause (Cont.) SQL allows duplicates in relations as well as in query results. To force the elimination of duplicates, insert the keyword distinct after select. Find the names of all branches in the loan relations, and remove duplicates select distinct branch-name from loan The keyword all specifies that duplicates not be removed. select all branch-name from loan

The select Clause(Cont) An asterisk in the select clause denotes all attributes select from loan The select clause can contain arithmetic expressions involving the operation, + -,* and / and operating on constants or attributes of tuples The query select loan-number, branch-name amount *s 100 from loan would return a relation which is the same as the loan relations, except that the attribute amount is multiplied by100 Database System Concepts 4.6 OSilberschatz. Korth and Sudarshan
Database System Concepts 4.6 ©Silberschatz, Korth and Sudarshan The select Clause (Cont.) An asterisk in the select clause denotes “all attributes” select * from loan The select clause can contain arithmetic expressions involving the operation, +, –, , and /, and operating on constants or attributes of tuples. The query: select loan-number, branch-name, amount 100 from loan would return a relation which is the same as the loan relations, except that the attribute amount is multiplied by 100

The where Clause The where clause specifies conditions that the result must satisfy corresponds to the selection predicate of the relational algebra To find all loan number for loans made at the Perryridge branch with loan amounts greater than $1200 select / oan-number from loan where branch-name Perryridge and amount>1200 Comparison results can be combined using the logical connectives and. or and not Database System Concepts 4.7 OSilberschatz. Korth and Sudarshan
Database System Concepts 4.7 ©Silberschatz, Korth and Sudarshan The where Clause The where clause specifies conditions that the result must satisfy corresponds to the selection predicate of the relational algebra. To find all loan number for loans made at the Perryridge branch with loan amounts greater than $1200. select loan-number from loan where branch-name = ‘Perryridge’ and amount > 1200 Comparison results can be combined using the logical connectives and, or, and not

The where Clause(Cont SQL includes a between comparison operator E.g. Find the loan number of those loans with loan amounts between $90,000 and $100,000 (that is, ≥$90,000and≤$100,000 select /oan-number from loan where amount between 90000 and 100000 标 Database System Concepts 4.8 OSilberschatz. Korth and Sudarshan
Database System Concepts 4.8 ©Silberschatz, Korth and Sudarshan The where Clause (Cont.) SQL includes a between comparison operator E.g. Find the loan number of those loans with loan amounts between $90,000 and $100,000 (that is, $90,000 and $100,000) select loan-number from loan where amount between 90000 and 100000

The from Clause The from clause lists the relations involved in the query corresponds to the Cartesian product operation of the relational algebra Find the cartesian product borrower x loan select from borrower oan Find the name loan number and loan amount of all customers having a loan at the Perryridge branch select customer-name, borrower oan-number amount from borrower loan where borrower oan-number= loan /oan-number and branch-name =Perryridge Database System Concepts 4.9 @Silberschatz, Korth and Sudarshan
Database System Concepts 4.9 ©Silberschatz, Korth and Sudarshan The from Clause The from clause lists the relations involved in the query corresponds to the Cartesian product operation of the relational algebra. Find the Cartesian product borrower x loan select from borrower, loan Find the name, loan number and loan amount of all customers having a loan at the Perryridge branch. select customer-name, borrower.loan-number, amount from borrower, loan where borrower.loan-number = loan.loan-number and branch-name = ‘Perryridge’

The Rename Operation The SQL allows renaming relations and attributes using the as clause old-name as new-name Find the name, loan number and loan amount of all customers: rename the column name loan-number as loan-jd select customer-name, borrower oan-number as loan-id. amount from borrower loan where borrower. oan-number loan loan-number Database System Concepts 4.10 @Silberschatz, Korth and Sudarshan
Database System Concepts 4.10 ©Silberschatz, Korth and Sudarshan The Rename Operation The SQL allows renaming relations and attributes using the as clause: old-name as new-name Find the name, loan number and loan amount of all customers; rename the column name loan-number as loan-id. select customer-name, borrower.loan-number as loan-id, amount from borrower, loan where borrower.loan-number = loan.loan-number
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 海南大学:《数据库原理及应用》课程PPT教学课件(英文版)Chapter 3 Relational Model.ppt
- 海南大学:《数据库原理及应用》课程PPT教学课件(英文版)Chapter 2 Entity-Relationship Model.ppt
- 海南大学:《数据库原理及应用》课程PPT教学课件(英文版)Chapter 1 Introduction(主讲:雷景生).ppt
- 上海理工大学:《电子商务基础与应用》课程PPT教学课件资源(第四版)第十一章 电子商务物流.ppt
- 《PLC》ppt电子书.ppt
- 浙江大学:《电子商务安全》课程PPT教学课件_第七章 防火墙的构造与选择.ppt
- 浙江大学:《电子商务安全》课程PPT教学课件_第六章 TCP/IP服务与WWW安全.ppt
- 浙江大学:《电子商务安全》课程PPT教学课件_第五章 密钥管理与数字证书.ppt
- 浙江大学:《电子商务安全》课程PPT教学课件_第三章 数字签名技术与应用.ppt
- 浙江大学:《电子商务安全》课程PPT教学课件_第一章 电子商务安全的现状和趋势.ppt
- 浙江大学:《电子商务安全》课程PPT教学课件_复习课.ppt
- 浙江大学:《电子商务安全》课程PPT教学课件_第九章 安全通信协议与交易协议.ppt
- 《网络系统集成技术》第9章 网络安全技术.ppt
- 《网络系统集成技术》第8章 网络管理技术.ppt
- 《网络系统集成技术》第7章 网络互联技术.ppt
- 《网络系统集成技术》第6章 综合布线技术.ppt
- 《网络系统集成技术》第5章 网络存储备份技术.ppt
- 《网络系统集成技术》第4章 网络服务器技术.ppt
- 《网络系统集成技术》第3章 常用的网络技术.ppt
- 《网络系统集成技术》第2章 网络基础知识.ppt
- 海南大学:《数据库原理及应用》课程PPT教学课件(英文版)Chapter 6 Integrity and Security.ppt
- 海南大学:《数据库原理及应用》课程PPT教学课件(英文版)Chapter 7 Relational Database Design.ppt
- 海南大学:《数据库原理及应用》课程PPT教学课件(英文版)Chapter 15 Transactions.ppt
- 海南大学:《数据库原理及应用》课程PPT教学课件(英文版)Chapter 16 Concurrency Control.ppt
- 《办公自动化—打印机》讲义.pps
- 《数值逼近》第一章 Weierstrass定理与线性算子逼近.doc
- 《数值逼近》第八章 曲线曲面生成与逼近.doc
- 《数值逼近》第七章 样条逼近方法.doc
- 《数值逼近》第六章 非线性逼近方法.doc
- 《数值逼近》第五章 数值积分.doc
- 《数值逼近》第四章 平方逼近.doc
- 《数值逼近》第三章 多项式插值方法.doc
- 《Internet应用基础》第2章 浏览器与电子邮件.ppt
- 《Internet应用基础》第3章 搜索引擎入门.ppt
- 《Internet应用基础》第4章 文件与下载.ppt
- 《Internet应用基础》第5章 网站建设与推广.ppt
- 《Internet应用基础》第6章 网络交流.ppt
- 《Internet应用基础》第7章 电子商务.ppt
- 《Internet应用基础》第8章 信息处理.ppt
- 《Internet应用基础》第9章 网站价值评估.ppt