Atitit sql之道 艾龙著 attilax 1. Ddl dml 3 2. Crud 3 3. 高级sql 3 3.1. Merge 3 3.2. 数据库翻页 limit offset系列

Atitit sql之道 艾龙著 attilax

 

 

1. Ddl dml 3

2. Crud 3

3. 高级sql 3

3.1. Merge 3

3.2. 数据库翻页  limit offset系列 3

3.3. Top 3

3.4. Like、与全文检索match 3

4. 语法Syntax[edit] 3

5. 连接 join 5

6. 聚合 5

7. 错误处理 5

8. 标准库函数 6

8.1. 加密解密与二进制转换函数 6

8.2. 数学系列 6

8.3. 字符串系列 6

8.4. 日期运算系列 6

8.5. 控制流程函数 条件判断函数; 6

8.6. 5 搜索函数 6

8.7. 6 加密函数 6

8.8. 7 信息函数 6

8.9. 8 其他函数 6

8.10. 9 聚合函数 6

8.11. 系统信息函数; 6

8.12. 格式化函数; 6

9. 数据库报表系统 7

10. 数据库Sql编程,存储过程sp,视图触发器 7

10.1. Sp存储过程 7

10.2. Udf自定义函数 7

10.3. Trigger触发器 7

10.4. View视图 7

10.5. 游标 7

11. Sql标准化 7

11.1. 1. Sql标准化的历史3 7

11.2. 1.1. Sql92标准4 7

11.3. 1.2. Sql99标准4 7

11.4. 1.3. SQL:2003为例,它包括以下9个部分5 7

11.5. 1.4. Sql2006标准6 7

11.6. 1.5. Sql2008标准7 7

11.7. 1.6. SQL:2011 7 8

11.8. sql:2016 8

11.9. 历年的sql标准化表 8

12. sql标准分为九个部分。 9

12.1. Alternatives[edit] 13

12.2. 备选方案[编辑] 16

12.3. Alternatives[edit] 16

13. Sql性能优化与explain 19

14. Sql解析与美化 19

14.1. 源码高亮 19

14.2. Sql解析 19

15. 常用的数据库算法 19

15.1. Join算法 19

15.2. Groupby算法 19

15.3. 聚合union算法 19

16. Atitit 业务逻辑的未来在于sql 19

17. sql扩展 plsql tsql 20

18. 关联知识点 20

19. sql-wikipedia 20

19.1. Contents 25

19.2. History[edit] 26

19.3. Design[edit] 27

19.4. Syntax[edit] 27

19.5. Procedural extensions[edit] 29

19.6. Interoperability and standardization[edit] 30

19.7. Alternatives[edit] 38

19.8. Distributed SQL processing[edit] 39

19.9. Criticisms[edit] 40

19.9.1. Orthogonality and completeness[edit] 40

19.9.2. Nulls[edit] 40

19.10. See also[edit] 40

19.11. 另见[编辑] 41

19.12. 注记 42

20. 参考资料 46

20.1. SQL 简介.mhtml 46

20.2. SQL - Wikipedia.mhtml 46

 

 

1. Ddl dml

2. Crud

3. 高级sql

3.1. Merge

3.2. 数据库翻页  limit offset系列

3.3. Top

3.4. Like、与全文检索match

 

4. 语法Syntax[edit]

Main article: SQL syntax

{\displaystyle \left.{\begin{array}{rl}\scriptstyle {\mathtt {UPDATE~clause}}&\{{\mathtt {UPDATE\ country}}\\\scriptstyle {\mathtt {SET~clause}}&\{{\mathtt {SET\ population=~}}\overbrace {\mathtt {population+1}} ^{\mathtt {expression}}\\\scriptstyle {\mathtt {WHERE~clause}}&\{{\mathtt {WHERE\ \underbrace {{name=}\overbrace {'USA'} ^{expression}} _{predicate};}}\end{array}}\right\}{\scriptstyle {\texttt {statement}}}}

A chart showing several of the SQL language elements that compose a single statement

The SQL language is subdivided into several language elements, including:

· Clauses, which are constituent components of statements and queries. (In some cases, these are optional.)[19]

· Expressions, which can produce either scalar values, or tables consisting of columns and rows of data

· Predicates, which specify conditions that can be evaluated to SQLthree-valued logic (3VL) (true/false/unknown) or Boolean truth valuesand are used to limit the effects of statements and queries, or to change program flow.

· Queries, which retrieve the data based on specific criteria. This is an important element of SQL.

· Statements, which may have a persistent effect on schemata and data, or may control transactions, program flow, connections, sessions, or diagnostics.

· SQL statements also include the semicolon (";") statement terminator. Though not required on every platform, it is defined as a standard part of the SQL grammar.

· Insignificant whitespace is generally ignored in SQL statements and queries, making it easier to format SQL code for readability.

sql语言被细分为几个语言元素,其中包括:

· 条款这是语句和查询的组成部分。(在某些情况下,这些是可选的)[19]

· 表达它可以产生标量值,或数据

· 谓词指定可对sql进行评估的条件。三值逻辑(3VL)(真实/假/未知)或布尔型真值并且用于限制语句和查询的效果,或者更改程序流。

· 查询检索基于特定标准的数据。这是一个重要的元素SQL...

· 陈述它可能会对模式和数据产生持久影响,或者可能控制交易程序流、连接、会话或诊断。

· sql语句还包括分号(“;”)声明终结者。虽然每个平台都不需要它,但它被定义为sql语法的标准部分。

· 无意义空白通常忽略sql语句和查询,从而更容易格式化sql代码以便于可读性。

 

 

5. 连接 join

 

6. 聚合

7. 错误处理

 

8. 标准库函数

8.1. 加密解密与二进制转换函数

8.2. 数学系列

8.3. 字符串系列

8.4. 日期运算系列

8.5. 控制流程函数 条件判断函数;

8.6.  5 搜索函数

8.7. 加密函数

8.8. 信息函数

8.9. 其他函数

8.10. 聚合函数

8.11. 系统信息函数;

8.12. 格式化函数;

 

 

 

 

9. 数据库报表系统

10. 数据库Sql编程,存储过程sp,视图触发器

10.1. Sp存储过程

10.2. Udf自定义函数

10.3. Trigger触发器

10.4. View视图

10.5. 游标

11. Sql标准化

11.1. 1. Sql标准化的历史3

11.2. 1.1. Sql92标准4

11.3. 1.2. Sql99标准4

11.4. 1.3. SQL:2003为例,它包括以下9个部分5

11.5. 1.4. Sql2006标准6

11.6. 1.5. Sql2008标准7

11.7. 1.6. SQL:2011 7

11.8.  href="https://en.wikipedia.org/wiki/SQL:2016" title="SQL:2016" sql:2016

 

2016年

sql:2016

 

添加行模式匹配、多态表函数、json。

11.9. 历年的sql标准化表

 

名称

化名

评论意见

一九八六年

SQL

SQL

首先由ansi形式化。

一九八九年

SQL

FIPS127-1

添加完整性约束的小修订,采用了作为127-1。

一九九二年

SQL

SQL2,FIPS 127-2

主要修订(Iso 9075),入门级SQL采用了作为127-2。

1999年

sql:1999

n.SQL3

添加正则表达式匹配,递归查询(如:传递闭包)触发器支持程序和控制流语句、非标量类型(数组)以及一些面向对象的特性(例如结构化类型那就是。支持将sql嵌入到java中(sql/OLB()反之亦然(sql/JRT)

2003年

sql:2003

 

介绍XML相关特性(sql/xml)窗口函数标准化序列,以及具有自动生成值的列(包括标识列)。

2006年

sql:2006

 

iso/iec 9075-14:2006定义了sql可以使用xml的方法。它定义了在sql数据库中导入和存储xml数据的方法,并在数据库中操作它,并以xml形式发布xml和常规sql数据。此外,它允许应用程序将查询集成到它们的sql代码中,XQuery由世界网联合会发布的xml查询语言(W3C),同时访问普通sql数据和xml文档。[31]

2008年

sql:2008

 

用外部游标定义进行命令行顺序。添加代替触发器,截断语句,[32]取条款。

2011年

sql:2011

 

添加时间数据(句点)[33](更多信息:时态数据库#历史那就是。增强窗口函数还有取条款。[34]

2016年

sql:2016

 

添加行模式匹配、多态表函数、json。

感兴趣的缔约方可以从iso购买sql标准文档,[35]iec或a

 

 

 

 

12. sql标准分为九个部分。

 

Interested parties may purchase SQL standards documents from ISO,[35]IEC or ANSI. A draft of SQL:2008 is freely available as a zip archive.[36]

The SQL standard is divided into nine parts.

· ISO/IEC 9075-1:2016 Part 1: Framework (SQL/Framework). It provides logical concepts.

· ISO/IEC 9075-2:2016 Part 2: Foundation (SQL/Foundation). It contains the most central elements of the language and consists of bothmandatory and optional features.

· ISO/IEC 9075-3:2016 Part 3: Call-Level Interface (SQL/CLI). It defines interfacing components (structures, procedures, variable bindings) that can be used to execute SQL statements from applications written in Ada, C respectively C++, COBOL, Fortran, MUMPS, Pascal or PL/I. (For Java see part 10.) SQL/CLI is defined in such a way that SQL statements and SQL/CLI procedure calls are treated as separate from the calling application's source code. Open Database Connectivity is a well-known superset of SQL/CLI. This part of the standard consists solely ofmandatory features.

· ISO/IEC 9075-4:2016 Part 4: Persistent stored modules (SQL/PSM). It standardizes procedural extensions for SQL, including flow of control, condition handling, statement condition signals and resignals, cursors and local variables, and assignment of expressions to variables and parameters. In addition, SQL/PSM formalizes declaration and maintenance of persistent database language routines (e.g., "stored procedures"). This part of the standard consists solely of optionalfeatures.

· Part-6Support for JavaScript Object Notation (JSON). In 2017 ISO/IEC published a first technical report about the effort to integrate the data type JSON into the SQL standard. Please consider that technical reports reflects the current state of the discussion and are not part of the standard.

· ISO/IEC 9075-9:2016 Part 9: Management of External Data (SQL/MED). It provides extensions to SQL that define foreign-data wrappers and datalink types to allow SQL to manage external data. External data is data that is accessible to, but not managed by, an SQL-based DBMS. This part of the standard consists solely of optional features.

· ISO/IEC 9075-10:2016 Part 10: Object language bindings (SQL/OLB). It defines the syntax and semantics of SQLJ, which is SQL embedded in Java (see also part 3). The standard also describes mechanisms to ensure binary portability of SQLJ applications, and specifies various Java packages and their contained classes. This part of the standard consists solely of optional features. Unlike SQL/OLB JDBC defines anAPI and is not part of the SQL standard.[citation needed]

· ISO/IEC 9075-11:2016 Part 11: Information and definition schemas(SQL/Schemata). It defines the Information Schema and Definition Schema, providing a common set of tools to make SQL databases and objects self-describing. These tools include the SQL object identifier, structure and integrity constraints, security and authorization specifications, features and packages of ISO/IEC 9075, support of features provided by SQL-based DBMS implementations, SQL-based DBMS implementation information and sizing items, and the values supported by the DBMS implementations.[37] This part of the standard contains both mandatory and optional features.

· ISO/IEC 9075-13:2016 Part 13: SQL Routines and types using the Java TM programming language (SQL/JRT). It specifies the ability to invoke static Java methods as routines from within SQL applications ('Java-in-the-database'). It also calls for the ability to use Java classes as SQL structured user-defined types. This part of the standard consists solely of optional features.

· ISO/IEC 9075-14:2016 Part 14: XML-Related Specifications (SQL/XML). It specifies SQL-based extensions for using XML in conjunction with SQL. The XML data type is introduced, as well as several routines, functions, and XML-to-SQL data type mappings to support manipulation and storage of XML in an SQL database.[31] This part of the standard consists solely of optional features.[citation needed]

ISO/IEC 9075 is complemented by ISO/IEC 13249 SQL Multimedia and Application Packages. This closely related but separate standard is developed by the same committee. It defines interfaces and packages based on SQL. The aim is a unified access to typical database applications like text, pictures, data mining or spatial data.

· ISO/IEC 13249-1:2016 Part 1: Framework

· ISO/IEC 13249-2:2003 Part 2: Full-Text

· ISO/IEC 13249-3:2016 Part 3: Spatial

· ISO/IEC 13249-5:2003 Part 5: Still image

· ISO/IEC 13249-6:2006 Part 6: Data mining

· ISO/IEC 13249-7:2013 Part 7: History

· ISO/IEC 13249-8:xxxx Part 8: Metadata Registry Access MRA (work in progress)

12.1. Alternatives[edit]

A distinction should be made between alternatives to SQL as a language, and alternatives to the relational model itself. Below are proposed relational alternatives to the SQL language. See navigational database andNoSQL for alternatives to the relational model.

· .QL: object-oriented Datalog

· 4D Query Language (4D QL)

 

· iso/iec 9075-1:2016部分第1部分:框架(sql/framework)。它提供逻辑概念。

· iso/iec 9075-2:2016部分2:基础(sql/foundation)。它包含了语言中最核心的元素,并且包含强制性和可选特征。

· iso/iec 9075-3:2016部分3:呼叫级接口(sql/cli那就是。它定义了接口组件(结构、程序、变量绑定),这些组件可以用于从ada、c、c+、cobol、fortran、流行性腮腺炎、pascal或pl/i中编写的应用程序中执行sql语句。(对于java而言,参见第10部分)。sql/cli定义方式是sql语句和sql/cli过程调用被视为与调用应用程序的源代码分离的。开放数据库连接sql/cli的一个众所周知的超集。该标准的这一部分仅由强制性特征。

· iso/iec 9075-4:2016部分第4部分:持久性存储模块(sql/psm那就是。它规范了sql的程序扩展,包括控制流、状态处理、语句条件信号和子参数、游标和局部变量以及变量和参数的表达式赋值。此外,sql/psm正式声明了持久化数据库语言例程的声明和维护(例如“存储过程”)。该标准的这一部分仅由任选特征。

· 第六部分支持javascript对象表示法(Json).。2017,iso/iec发布了关于将数据类型json集成到sql标准中的第一项技术报告。请考虑技术报告反映了讨论的现状,而不是标准的一部分。

· iso/iec 9075-9:2016部分9:外部数据管理(sql/med那就是。它提供了对sql的扩展,该扩展定义了外部数据包装器和数据链类型,以允许sql管理外部数据。外部数据是一个可访问但未管理的sql数据库dbms的数据。该标准的这一部分仅由任选特征。

· iso/iec 9075-10:2016部分第10部分:对象语言绑定(sql/OLB那就是。它定义了语法和语义SQLJ这是java嵌入的java(参见第3部分)。该标准还描述了确保SQLJ应用程序二进制可移植性的机制,并指定了各种java包及其包含的类。该标准的这一部分仅由任选特征。与sql/OLB不同。JDBC定义API也不是sql标准的一部分。[所需引文]

· iso/iec 9075-11:2016部分11:信息和定义模式(sql/图式那就是。它定义了信息架构和定义架构,提供了一套通用的工具来实现sql数据库和对象的自描述。这些工具包括sql对象标识符、结构和完整性约束、安全和授权规范、iso/iec 9075的功能和包、支持sql数据库实现提供的特性、基于sql的dbms实现信息和大小参数项以及dbms实现所支持的值。[37]该标准的这一部分包含强制性和可选特征。

· iso/iec 9075-13:2016第13部分:使用java tm编程语言编写sql例程和类型(sql/JRT那就是。它指定了将静态java方法作为例程调用sql应用程序(“数据库-数据库”)的能力。它还要求使用java类作为sql结构化用户定义类型的能力。该标准的这一部分仅由任选特征。

· iso/iec 9075-14:2016部分14:xml相关的规范(sql/xml那就是。它指定了基于sql的扩展,用于使用xml与sql一起使用。|||XML介绍了数据类型,以及几个例程、函数和xml到sql数据类型映射来支持sql数据库中xml的操作和存储。[31]该标准的这一部分仅由任选特征。[所需引文]

iso/iec 9075由iso/iec 13249补充sql多媒体和应用软件包.。这一密切相关但又独立的标准由同一委员会制定。它定义了基于sql的接口和包。其目的是统一访问典型数据库应用程序,如文本、图片、数据挖掘或空间数据...

· iso/iec 13249-1:2016部分第1部分:框架

· iso/iec 13249-2:2003部分2:全文

· iso/iec 13249-3:2016部分3:空间

· iso/iec 13249-5:2003部分第5部分:静止图像

· iso/iec 13249-6:2006部分6:数据挖掘

· iso/iec 13249-7:2013部分7:历史

· iso/iec 13249-8:xxxx部分8:元数据注册表访问 MRA(正在进行中)

12.2. 备选方案[编辑]

应该区分作为语言的sql替代物

 

· gress)

12.3. Alternatives[edit]

A distinction should be made between alternatives to SQL as a language, and alternatives to the relational model itself. Below are proposed relational alternatives to the SQL language. See navigational database andNoSQL for alternatives to the relational model.

· .QL: object-oriented Datalog

· 4D Query Language (4D QL)

· BQL: a superset that compiles down to SQL

· Datalog: critics suggest that Datalog has two advantages over SQL: it has cleaner semantics, which facilitates program understanding and maintenance, and it is more expressive, in particular for recursive queries.[38]

· HTSQL: URL based query method

· IBM Business System 12 (IBM BS12): one of the first fully relational database management systems, introduced in 1982

· ISBL

· jOOQ: SQL implemented in Java as an internal domain-specific language

· Java Persistence Query Language (JPQL): The query language used by the Java Persistence API and Hibernate persistence library

· LINQ: Runs SQL statements written like language constructs to query collections directly from inside .Net code.

· Object Query Language

· QBE (Query By Example) created by Moshè Zloof, IBM 1977

· Quel introduced in 1974 by the U.C. Berkeley Ingres project.

· Tutorial D

· XQuery

应该区分作为语言的sql替代物和关系模型本身的替代方法。下面是sql语言中的关系式替代方案。见导航数据库NoSQL对于关系模型的替代方法。

· n..QL:面向对象的电子邮件

· 四维查询语言(4d QL)

· n.BQL:将编译到sql的超集

· n.Datalog评论家们认为n.Datalogsql有两个优点:它具有更干净的语义,这有助于程序理解和维护,而且它更具有表现力,尤其是递归查询。[38]

· n.HTSQL基于url的查询方法

· ibm业务系统12(Ibm BS12):第一个完全关系数据库管理系统之一,于1982引入

· n.ISBL

· JOOQsql在java中实现为内部域特定语言

· java持久性查询语言(JPQL):java持久性api使用的查询语言和冬眠持久性库

· 林克:运行sql语句,如语言构造那样直接从内部查询集合。.net密码。

· 对象查询语言

· QBE(以实例查询ibm 1977公司创建的

· 奎尔1974由伯克利大学伯克利分校项目介绍。

· 教程d

· XQuery

 

 

13. Sql性能优化与explain

14. Sql解析与美化

14.1. 源码高亮

14.2. Sql解析

15. 常用的数据库算法

15.1. Join算法

15.2. Groupby算法

15.3. 聚合union算法

 

16. Atitit 业务逻辑的未来在于sql

 

界面guidsl就是h5了。。

数据库就是sql了。。

中间的业务逻辑dsl,一直群星着陆,目前还没有个标准化统一的。。目前貌似主流java为主。Sql,工作流图形化dsl, 脚本js 等都部分的分站了部分的业务逻辑。。

 

为什么业务逻辑的dsl如此的繁复。。不像sql一样很早 就统一了。。Gui方面的今年也基本统一了。。现在就差业务方面的dsl了。。

 

我想,可能是业务系统绝大部分要操作数据库。。这导致了很难发明堪比sqldsl,而且又足够通用的dsl。。。

 

 

17.  sql扩展 plsql tsql

 

18. 关联知识点

19. sql-wikipedia

This article is about the database language. For the IATA code, see San Carlos Airport (California).

"SEQUEL" redirects here. For the topic of the word, see sequel. For other uses, see sequel (disambiguation).

SQL

Paradigm

Multi-paradigm:declarative

Family

Programming language

Designed by

Donald D. Chamberlin

Raymond F. Boyce

Developer

ISO/IEC

First appeared

1974; 44 years ago

Typing discipline

Staticstrong

OS

Cross-platform

File formats

File format details

Filename extension

.sql

Internet media type

application/sql[1][2]

Developed by

ISO/IEC

Initial release

1986

Latest release

SQL:2016

(December 2016; 1 year ago)

Type of format

Database

Standard

ISO/IEC 9075

Open format?

Yes

Major implementations

Many

Dialects

· SQL-86

· SQL-89

· SQL-92

· SQL:1999

· SQL:2003

· SQL:2006

· SQL:2008

· SQL:2011

· SQL:2016

Influenced by

Datalog

Influenced

CQLLINQSOQLPowerShell,[3] JPQLjOOQ,N1QL

· Structured Query Language at Wikibooks

SQL(/ˌɛs.kjuːˈɛl/ ( listen)S-Q-L,[4] /ˈsiːkwəl/ "sequel"; Structured Query Language)[5][6][7][8] is adomain-specific language used in programming and designed for managing data held in a relational database management system(RDBMS), or for stream processing in a relational data stream management system (RDSMS). In comparison to older read/write APIs like ISAM orVSAM, SQL offers two main advantages: first, it introduced the concept of accessing many records with one single command; and second, it eliminates the need to specify how to reach a record, e.g. with or without an index.

Originally based upon relational algebra and tuple relational calculus, SQL consists of many types of statements,[9] which may be informally classed as sublanguages, commonly: a data query language (DQL),[a] a data definition language (DDL),[b] a data control language (DCL), and a data manipulation language (DML)[c].[10] The scope of SQL includes data query, data manipulation (insert, update and delete), data definition (schemacreation and modification), and data access control. Although SQL is often described as, and to a great extent is, a declarative language (4GL), it also includes procedural elements.

SQL was one of the first commercial languages for Edgar F. Codd'srelational model, as described in his influential 1970 paper, "A Relational Model of Data for Large Shared Data Banks".[11] Despite not entirely adhering to the relational model as described by Codd, it became the most widely used database language.[12][13]

SQL became a standard of the American National Standards Institute(ANSI) in 1986, and of the International Organization for Standardization(ISO) in 1987.[14] Since then, the standard has been revised to include a larger set of features. Despite the existence of such standards, most SQL code is not completely portable among different database systems without adjustments.

19.1. Contents

· 1History

· 2Design

· 3Syntax

· 4Procedural extensions

· 5Interoperability and standardization

· 6Alternatives

· 7Distributed SQL processing

· 8Criticisms

· 8.1Orthogonality and completeness

· 8.2Nulls

· 9See also

· 10Notes

· 11References

· 12External links

19.2. History[edit]

SQL was initially developed at IBM by Donald D. Chamberlin and Raymond F. Boyce after learning about the relational model from Ted Codd[15] in the early 1970s.[16] This version, initially called SEQUEL (Structured English Query Language), was designed to manipulate and retrieve data stored in IBM's original quasi-relational database management system, System R, which a group at IBM San Jose Research Laboratory had developed during the 1970s.[16]

Chamberlin and Boyce's first attempt of a relational database language was Square, but it was difficult to use due to subscript notation. After moving to the San Jose Research Laboratory in 1973, they began work on SEQUEL.[15]The acronym SEQUEL was later changed to SQL because "SEQUEL" was atrademark of the UK-based Hawker Siddeley aircraft company.[17]

In the late 1970s, Relational Software, Inc. (now Oracle Corporation) saw the potential of the concepts described by Codd, Chamberlin, and Boyce, and developed their own SQL-based RDBMS with aspirations of selling it to the U.S. NavyCentral Intelligence Agency, and other U.S. governmentagencies. In June 1979, Relational Software, Inc. introduced the first commercially available implementation of SQL, Oracle V2 (Version2) forVAX computers. By the year 1986, ANSI and ISO standard groups officially adopted the standard "Database Language SQL" language definition. New versions of the standard were published in 1996, 1999, 2003, 2006, 2008, 2011, and most recently, 2016. [15]

After testing SQL at customer test sites to determine the usefulness and practicality of the system, IBM began developing commercial products based on their System R prototype including System/38SQL/DS, and DB2, which were commercially available in 1979, 1981, and 1983, respectively.[18]

19.3. Design[edit]

SQL deviates in several ways from its theoretical foundation, the relational model and its tuple calculus. In that model, a table is a set of tuples, while in SQL, tables and query results are lists of rows: the same row may occur multiple times, and the order of rows can be employed in queries (e.g. in the LIMIT clause).

Critics argue that SQL should be replaced with a language that strictly returns to the original foundation: for example, see The Third Manifesto.

19.4. Syntax[edit]

Main article: SQL syntax

{\displaystyle \left.{\begin{array}{rl}\scriptstyle {\mathtt {UPDATE~clause}}&\{{\mathtt {UPDATE\ country}}\\\scriptstyle {\mathtt {SET~clause}}&\{{\mathtt {SET\ population=~}}\overbrace {\mathtt {population+1}} ^{\mathtt {expression}}\\\scriptstyle {\mathtt {WHERE~clause}}&\{{\mathtt {WHERE\ \underbrace {{name=}\overbrace {'USA'} ^{expression}} _{predicate};}}\end{array}}\right\}{\scriptstyle {\texttt {statement}}}}

A chart showing several of the SQL language elements that compose a single statement

The SQL language is subdivided into several language elements, including:

· Clauses, which are constituent components of statements and queries. (In some cases, these are optional.)[19]

· Expressions, which can produce either scalar values, or tables consisting of columns and rows of data

· Predicates, which specify conditions that can be evaluated to SQLthree-valued logic (3VL) (true/false/unknown) or Boolean truth valuesand are used to limit the effects of statements and queries, or to change program flow.

· Queries, which retrieve the data based on specific criteria. This is an important element of SQL.

· Statements, which may have a persistent effect on schemata and data, or may control transactions, program flow, connections, sessions, or diagnostics.

· SQL statements also include the semicolon (";") statement terminator. Though not required on every platform, it is defined as a standard part of the SQL grammar.

· Insignificant whitespace is generally ignored in SQL statements and queries, making it easier to format SQL code for readability.

19.5. Procedural extensions[edit]

SQL is designed for a specific purpose: to query data contained in arelational database. SQL is a set-based, declarative programming language, not an imperative programming language like C or BASIC. However, extensions to Standard SQL add procedural programming languagefunctionality, such as control-of-flow constructs. These include:

Source

Common name

Full name

ANSI/ISO Standard

SQL/PSM

SQL/Persistent Stored Modules

Interbase /Firebird

PSQL

Procedural SQL

IBM DB2

SQL PL

SQL Procedural Language (implements SQL/PSM)

IBM Informix

SPL

Stored Procedural Language

IBMNetezza

NZPLSQL[20]

(based on Postgres PL/pgSQL)

Microsoft /Sybase

T-SQL

Transact-SQL

Mimer SQL

SQL/PSM

SQL/Persistent Stored Module (implements SQL/PSM)

MySQL

SQL/PSM

SQL/Persistent Stored Module (implements SQL/PSM)

MonetDB

SQL/PSM

SQL/Persistent Stored Module (implements SQL/PSM)

NuoDB

SSP

Starkey Stored Procedures

Oracle

PL/SQL

Procedural Language/SQL (based on Ada)

PostgreSQL

PL/pgSQL

Procedural Language/PostgreSQL Structured Query Language (implements SQL/PSM)

Sybase

Watcom-SQL

SQL Anywhere Watcom-SQL Dialect

Teradata

SPL

Stored Procedural Language

SAP

SAP HANA

SQL Script

In addition to the standard SQL/PSM extensions and proprietary SQL extensions, procedural and object-oriented programmability is available on many SQL platforms via DBMS integration with other languages. The SQL standard defines SQL/JRT extensions (SQL Routines and Types for the Java Programming Language) to support Java code in SQL databases. SQL Server 2005 uses the SQLCLR (SQL Server Common Language Runtime) to host managed .NET assemblies in the database, while prior versions of SQL Server were restricted to unmanaged extended stored procedures primarily written in C. PostgreSQL lets users write functions in a wide variety of languages—including PerlPythonTclJavaScript (PL/V8) and C.[21]

19.6. Interoperability and standardization[edit]

SQL implementations are incompatible between vendors and do not necessarily completely follow standards. In particular date and time syntax, string concatenation, NULLs, and comparison case sensitivity vary from vendor to vendor. Particular exceptions are PostgreSQL[22] and Mimer SQL[23] who strive for standards compliance.

Popular implementations of SQL commonly omit support for basic features of Standard SQL, such as the DATE or TIME data types. The most obvious such examples, and incidentally the most popular commercial and proprietary SQL DBMSs, are Oracle (whose DATE behaves asDATETIME,[24][25] and lacks a TIME type)[26] and MS SQL Server (before the 2008 version). As a result, SQL code can rarely be ported between database systems without modifications.

There are several reasons for this lack of portability between database systems:

· The complexity and size of the SQL standard means that most implementors do not support the entire standard.

· The standard does not specify database behavior in several important areas (e.g. indexes, file storage...), leaving implementations to decide how to behave.

· The SQL standard precisely specifies the syntax that a conforming database system must implement. However, the standard's specification of the semantics of language constructs is less well-defined, leading to ambiguity.

· Many database vendors have large existing customer bases; where the newer version of the SQL standard conflicts with the prior behavior of the vendor's database, the vendor may be unwilling to break backward compatibility.

· There is little commercial incentive for vendors to make it easier for users to change database suppliers (see vendor lock-in).

· Users evaluating database software tend to place other factors such as performance higher in their priorities than standards conformance.

SQL was adopted as a standard by the American National Standards Institute (ANSI) in 1986 as SQL-86[27] and the International Organization for Standardization (ISO) in 1987. It is maintained by ISO/IEC JTC 1, Information technology, Subcommittee SC 32, Data management and interchange. The standard is commonly denoted by the pattern: ISO/IEC 9075-n:yyyy Part n: title, or, as a shortcut, ISO/IEC 9075.

ISO/IEC 9075 is complemented by ISO/IEC 13249: SQL Multimedia and Application Packages (SQL/MM), which defines SQL based interfaces and packages to widely spread applications like video, audio and spatial data.

Until 1996, the National Institute of Standards and Technology (NIST) data management standards program certified SQL DBMS compliance with the SQL standard. Vendors now self-certify the compliance of their products.[28]

The original standard declared that the official pronunciation for "SQL" was an initialism/ˈɛskjuːˈɛl/ ("es queue el").[12] Regardless, many English-speaking database professionals (including Donald Chamberlin himself[29]) use the acronym-like pronunciation of /ˈsiːkwəl/ ("sequel"),[30] mirroring the language's pre-release development name of "SEQUEL".[16][17][29][16]The SQL standard has gone through a number of revisions:

Year

Name

Alias

Comments

1986

SQL-86

SQL-87

First formalized by ANSI.

1989

SQL-89

FIPS127-1

Minor revision that added integrity constraints, adopted as FIPS 127-1.

1992

SQL-92

SQL2, FIPS 127-2

Major revision (ISO 9075), Entry Level SQL-92 adopted as FIPS 127-2.

1999

SQL:1999

SQL3

Added regular expression matching, recursive queries (e.g. transitive closure), triggers, support for procedural and control-of-flow statements, non-scalar types (arrays), and some object-oriented features (e.g. structured types). Support for embedding SQL in Java (SQL/OLB) and vice versa (SQL/JRT).

2003

SQL:2003

 

Introduced XML-related features (SQL/XML),window functions, standardized sequences, and columns with auto-generated values (including identity-columns).

2006

SQL:2006

 

ISO/IEC 9075-14:2006 defines ways that SQL can be used with XML. It defines ways of importing and storing XML data in an SQL database, manipulating it within the database, and publishing both XML and conventional SQL-data in XML form. In addition, it lets applications integrate queries into their SQL code with XQuery, the XML Query Language published by the World Wide Web Consortium (W3C), to concurrently access ordinary SQL-data and XML documents.[31]

2008

SQL:2008

 

Legalizes ORDER BY outside cursor definitions. Adds INSTEAD OF triggers, TRUNCATE statement,[32] FETCH clause.

2011

SQL:2011

 

Adds temporal data (PERIOD FOR)[33] (more information at: Temporal database#History). Enhancements for window functions and FETCH clause.[34]

2016

SQL:2016

 

Adds row pattern matching, polymorphic table functions, JSON.

Interested parties may purchase SQL standards documents from ISO,[35]IEC or ANSI. A draft of SQL:2008 is freely available as a zip archive.[36]

The SQL standard is divided into nine parts.

· ISO/IEC 9075-1:2016 Part 1: Framework (SQL/Framework). It provides logical concepts.

· ISO/IEC 9075-2:2016 Part 2: Foundation (SQL/Foundation). It contains the most central elements of the language and consists of bothmandatory and optional features.

· ISO/IEC 9075-3:2016 Part 3: Call-Level Interface (SQL/CLI). It defines interfacing components (structures, procedures, variable bindings) that can be used to execute SQL statements from applications written in Ada, C respectively C++, COBOL, Fortran, MUMPS, Pascal or PL/I. (For Java see part 10.) SQL/CLI is defined in such a way that SQL statements and SQL/CLI procedure calls are treated as separate from the calling application's source code. Open Database Connectivity is a well-known superset of SQL/CLI. This part of the standard consists solely ofmandatory features.

· ISO/IEC 9075-4:2016 Part 4: Persistent stored modules (SQL/PSM). It standardizes procedural extensions for SQL, including flow of control, condition handling, statement condition signals and resignals, cursors and local variables, and assignment of expressions to variables and parameters. In addition, SQL/PSM formalizes declaration and maintenance of persistent database language routines (e.g., "stored procedures"). This part of the standard consists solely of optionalfeatures.

· Part-6Support for JavaScript Object Notation (JSON). In 2017 ISO/IEC published a first technical report about the effort to integrate the data type JSON into the SQL standard. Please consider that technical reports reflects the current state of the discussion and are not part of the standard.

· ISO/IEC 9075-9:2016 Part 9: Management of External Data (SQL/MED). It provides extensions to SQL that define foreign-data wrappers and datalink types to allow SQL to manage external data. External data is data that is accessible to, but not managed by, an SQL-based DBMS. This part of the standard consists solely of optional features.

· ISO/IEC 9075-10:2016 Part 10: Object language bindings (SQL/OLB). It defines the syntax and semantics of SQLJ, which is SQL embedded in Java (see also part 3). The standard also describes mechanisms to ensure binary portability of SQLJ applications, and specifies various Java packages and their contained classes. This part of the standard consists solely of optional features. Unlike SQL/OLB JDBC defines anAPI and is not part of the SQL standard.[citation needed]

· ISO/IEC 9075-11:2016 Part 11: Information and definition schemas(SQL/Schemata). It defines the Information Schema and Definition Schema, providing a common set of tools to make SQL databases and objects self-describing. These tools include the SQL object identifier, structure and integrity constraints, security and authorization specifications, features and packages of ISO/IEC 9075, support of features provided by SQL-based DBMS implementations, SQL-based DBMS implementation information and sizing items, and the values supported by the DBMS implementations.[37] This part of the standard contains both mandatory and optional features.

· ISO/IEC 9075-13:2016 Part 13: SQL Routines and types using the Java TM programming language (SQL/JRT). It specifies the ability to invoke static Java methods as routines from within SQL applications ('Java-in-the-database'). It also calls for the ability to use Java classes as SQL structured user-defined types. This part of the standard consists solely of optional features.

· ISO/IEC 9075-14:2016 Part 14: XML-Related Specifications (SQL/XML). It specifies SQL-based extensions for using XML in conjunction with SQL. The XML data type is introduced, as well as several routines, functions, and XML-to-SQL data type mappings to support manipulation and storage of XML in an SQL database.[31] This part of the standard consists solely of optional features.[citation needed]

ISO/IEC 9075 is complemented by ISO/IEC 13249 SQL Multimedia and Application Packages. This closely related but separate standard is developed by the same committee. It defines interfaces and packages based on SQL. The aim is a unified access to typical database applications like text, pictures, data mining or spatial data.

· ISO/IEC 13249-1:2016 Part 1: Framework

· ISO/IEC 13249-2:2003 Part 2: Full-Text

· ISO/IEC 13249-3:2016 Part 3: Spatial

· ISO/IEC 13249-5:2003 Part 5: Still image

· ISO/IEC 13249-6:2006 Part 6: Data mining

· ISO/IEC 13249-7:2013 Part 7: History

· ISO/IEC 13249-8:xxxx Part 8: Metadata Registry Access MRA (work in progress)

19.7. Alternatives[edit]

A distinction should be made between alternatives to SQL as a language, and alternatives to the relational model itself. Below are proposed relational alternatives to the SQL language. See navigational database andNoSQL for alternatives to the relational model.

· .QL: object-oriented Datalog

· 4D Query Language (4D QL)

· BQL: a superset that compiles down to SQL

· Datalog: critics suggest that Datalog has two advantages over SQL: it has cleaner semantics, which facilitates program understanding and maintenance, and it is more expressive, in particular for recursive queries.[38]

· HTSQL: URL based query method

· IBM Business System 12 (IBM BS12): one of the first fully relational database management systems, introduced in 1982

· ISBL

· jOOQ: SQL implemented in Java as an internal domain-specific language

· Java Persistence Query Language (JPQL): The query language used by the Java Persistence API and Hibernate persistence library

· LINQ: Runs SQL statements written like language constructs to query collections directly from inside .Net code.

· Object Query Language

· QBE (Query By Example) created by Moshè Zloof, IBM 1977

· Quel introduced in 1974 by the U.C. Berkeley Ingres project.

· Tutorial D

· XQuery

19.8. Distributed SQL processing[edit]

Distributed Relational Database Architecture (DRDA) was designed by a work group within IBM in the period 1988 to 1994. DRDA enables network connected relational databases to cooperate to fulfill SQL requests.[39][40]

An interactive user or program can issue SQL statements to a local RDB and receive tables of data and status indicators in reply from remote RDBs. SQL statements can also be compiled and stored in remote RDBs as packages and then invoked by package name. This is important for the efficient operation of application programs that issue complex, high-frequency queries. It is especially important when the tables to be accessed are located in remote systems.

The messages, protocols, and structural components of DRDA are defined by the Distributed Data Management Architecture.

19.9. Criticisms[edit]

Chamberlin's critiques of SQL include:

19.9.1. Orthogonality and completeness[edit]

Early specifications did not support major features, such as primary keys. Result sets could not be named, and subqueries had not been defined. These were added in 1992.[15]

19.9.2. Nulls[edit]

SQL's controversial "null" value is neither true nor false (predicates with terms that return a null value return null rather than true or false). Features such as outer-join depend on null values.[15]

Other popular critiques are that it allows duplicate rows, integrating with a languages such as Python, whose data types are not the same, [15] difficulty of parsing and the absence of modularity.[41]

19.10. See also[edit]

 

· Book: SQL

· Comparison of object-relational database management systems

· Comparison of relational database management systems

· D (data language specification)

· D4 (programming language)

· Hierarchical model

· List of relational database management systems

· MUMPS

· NoSQL

· Transact-SQL

· Online analytical processing (OLAP)

· Online transaction processing (OLTP)

· Data warehouse

· Relational data stream management system

· Star schema

· Snowflake schema

 

19.11. 另见[编辑]

 

· 书:sql

· 对象关系数据库管理系统的比较

· 关系数据库管理系统的比较

· 数据语言规范

· d4(程序设计语言)

· 层次模型

· 关系数据库管理系统列表

· 腮腺炎

· NoSQL

· transact-sql-sql

· 在线分析处理(Olap)

· 联机事务处理(Oltp)

· 数据仓库

· 关系数据流管理系统

· 星型模式

· 雪花图式

19.12. 注记

 

 

SQL

Versions

· SQL-86

· SQL-89

· SQL-92

· SQL:1999

· SQL:2003

· SQL:2006

· SQL:2008

· SQL:2011

· SQL:2016

Keywords

· As

· Case

· Create

· Delete

· From

· Having

· Insert

· Join

· Merge

· Null

· Order by

· Prepare

· Select

· Truncate

· Union

· Update

· Where

· With

Related

· Edgar Codd

· Relational database

ISO/IEC SQL parts

· Framework

· Foundation

· Call-Level Interface

· Persistent Stored Modules

· Management of External Data

· Object Language Bindings

· Information and Definition Schemas

· SQL Routines and Types for the Java Programming Language

· XML-Related Specifications

 

 

 

Database management systems

Types

· Object-oriented 

· comparison

 

· Relational 

· comparison

 

· Document-oriented

· Graph

· NoSQL

· NewSQL

Concepts

· Database

· ACID

· Armstrong's axioms

· CAP theorem

· CRUD

· Null

· Candidate key

· Foreign key

· Superkey

· Surrogate key

· Unique key

Objects

· Relation 

· table

· column

· row

 

· View

· Transaction

· Transaction log

· Trigger

· Index

· Stored procedure

· Cursor

· Partition

Components

· Concurrency control

· Data dictionary

· JDBC

· XQJ

· ODBC

· Query language

· Query optimizer

· Query plan

Functions

· Administration and automation

· Query optimization

· Replication

Related topics

· Database models

· Database normalization

· Database storage

· Distributed database

· Federated database system

· Referential integrity

· Relational algebra

· Relational calculus

· Relational database

· Relational DBMS

· Relational model

 

 

Query languages

In current use

· .QL

· ALPHA

· CQL

· Cypher

· D

· DMX

· Datalog

· Gremlin

· ISBL

· LDAP

· LINQ

· MQL

· MDX

· OQL

· OCL

· QUEL

· SMARTS

· SPARQL

· SQL

· XQuery

· XPath

Proprietary

· YQL

Superseded

· CODASYL

 

20. 参考资料

20.1. SQL 简介.mhtml

20.2. SQL - Wikipedia.mhtml

posted @ 2018-02-21 12:39  attilaxAti  阅读(32)  评论(0编辑  收藏  举报