History
SQL was initially developed at IBM by Donald D. Chamberlin and Raymond F. Boyce after learning about the relational model from Edgar F. Codd in the early 1970s. This version, initially called SEQUEL (Structured English Query Language), was designed to manipulate and retrieve data stored in IBM's original quasirelational database management system, System R, which a group at IBM San Jose Research Laboratory had developed during the 1970s. Chamberlin and Boyce's first attempt at a relational database language was SQUARE (Specifying Queries in A Relational Environment), but it was difficult to use due to subscript/superscript notation. After moving to the San Jose Research Laboratory in 1973, they began work on a sequel to SQUARE. The original name SEQUEL, which is widely regarded as a pun on QUEL, the query language of Ingres, was later changed to SQL (dropping the vowels) because "SEQUEL" was a trademark of the UK-based Hawker Siddeley Dynamics Engineering Limited company. The label SQL later became the acronym for Structured Query Language. 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/38, SQL/DS, and IBM Db2, which were commercially available in 1979, 1981, and 1983, respectively. IBM's endorsement caused the industry to move to SQL from alternatives like QUEL. 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. Navy, Central Intelligence Agency, and other U.S. government agencies. In June 1979, Relational Software introduced one of the first commercially available implementations of SQL, Oracle V2 (Version2) for
Interoperability and standardization
SQL language revisions SQL-86 SQL-89 SQL-92 SQL:1999 SQL:2003 SQL:2006 SQL:2008 SQL:2011 SQL:2016 SQL:2019 SQL:2023 vte SQL compliance Overview 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. PostgreSQL and Mimer SQL strive for standards compliance, though PostgreSQL does not adhere to the standard in all cases. For example, the folding of unquoted names to lower case in PostgreSQL is incompatible with the SQL standard, which says that unquoted names should be folded to upper case. Thus, according to the standard, Foo should be equivalent to FOO, not foo. 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 as DATETIME, and lacks a TIME type) and MS SQL Server (before the 2008 version). As a result, SQL code can rarely be ported between database systems without modifications. Reasons for incompatibility Several reasons for the lack of portability between database systems include: The complexity and size of the SQL standard means that most implementers do not support the entire standard. The SQL standard does not specify the database behavior in some important areas (e.g., indices, file storage), leaving implementations to decide how to behave. The SQL standard defers some decisions to individual implementations, such as how to name a results column that was not named explicitly.: 207 The SQL standard precisely specifies the syntax that a conforming database system mu
Syntax
SQL syntax U P D A T E c l a u s e : S E T c l a u s e : W H E R E c l a u s e : ; } statement ⏟ S Q L q u e r y {\displaystyle \underbrace {\left.{\begin{array}{rl}\textstyle {\mathtt {UPDATEclause{\mathtt {:}}}}&{{\mathtt {UPDATE\ \overbrace {\mathtt {countries}} ^{\mathtt {table}}}}}\\textstyle {\mathtt }&{{{\mathtt {SET\ \overbrace {\mathtt } ^{\mathtt {column}}=}}\overbrace {\mathtt {+\underbrace {\mathtt {1}} _{\mathtt {literal}}}} ^{\mathtt }}}\\textstyle {\mathtt }&{{{\mathtt {WHERE\ \underbrace {\overbrace {\mathtt {name}} ^{\mathtt {column}}{\mathtt {=}}\overbrace {\overbrace {\mathtt {'USA'}} ^{\mathtt {literal}}} ^{\mathtt }} _{\mathtt {predicate}}}}}{\texttt {;}}}\end{array}}\right}{\textstyle {\texttt {statement}}}} _{\textstyle {\mathtt {SQL~query}}}} A chart showing several of the SQL language elements comprising 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.) 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 SQL three-valued logic (3VL) (true/false/unknown) or Boolean truth values and 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 o
Procedural extensions
SQL is designed for a specific purpose: to query data contained in a relational 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 language functionality, such as control-of-flow constructs. 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. Microsoft 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 Perl, Python, Tcl, JavaScript (PL/V8) and C.
Alternatives
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 and NoSQL for alternatives to the relational model. .div-col.div-col-small.div-col-rules.div-col dl,.div-col ol,.div-col ul.div-col li,.div-col dd .QL: object-oriented Datalog 4D Query Language (4D QL) 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. 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 JavaScript: MongoDB implements its query language in a JavaScript API. 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, closer to tuple relational calculus than SQL XQuery
Distributed SQL processing
Distributed Relational Database Architecture (DRDA) was designed by a workgroup within IBM from 1988 to 1994. DRDA enables network-connected relational databases to cooperate to fulfill SQL requests. 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. Distributed SQL processing ala DRDA is distinctive from contemporary distributed SQL databases.
Criticisms
Design 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 returns strictly to the original foundation: for example, see The Third Manifesto by Hugh Darwen and C.J. Date (2006, q.citation:target.id-lock-free.id-lock-free a.id-lock-limited.id-lock-limited a,.id-lock-registration.id-lock-registration a.id-lock-subscription.id-lock-subscription a.cs1-ws-icon abody:not(.skin-timeless):not(.skin-minerva) .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .cs1-ws-icon a.cs1-code{color:inherit;background:inherit;border:none;padding:i
SQL data types
The SQL standard defines three kinds of data types (chapter 4.1.1 of SQL/Foundation): predefined data types constructed types user-defined types. Constructed types are one of ARRAY, MULTISET, REF (reference), or ROW. User-defined types are comparable to classes in object-oriented language with their own constructors, observers, mutators, methods, inheritance, overloading, overwriting, interfaces, and so on. Predefined data types are intrinsically supported by the implementation. Predefined data types Character types Character (CHAR) Character varying (VARCHAR) Character large object (CLOB) National character types National character (NCHAR) National character varying (NCHAR VARYING) National character large object (NCLOB) Binary types Binary (BINARY) Binary varying (VARBINARY) Binary large object (BLOB) Numeric types Exact numeric types (NUMERIC, DECIMAL, SMALLINT, INTEGER, BIGINT) Approximate numeric types (FLOAT, REAL, DOUBLE PRECISION) Decimal floating-point type (DECFLOAT) Datetime types (DATE, TIME, TIMESTAMP) Interval type (INTERVAL) Boolean XML (see SQL/XML) JSON