(This is stale and you may wish to find a more up-to-date copy, but it is preserved here for posterity. Enjoy -- Daria 24 Nov 2017) Information Technology - Database Language SQL (Proposed revised text of DIS 9075) July 1992 (Second Informal Review Draft) ISO/IEC 9075:1992, Database Language SQL- July 30, 1992 Digital Equipment Corporation Maynard, Massachusetts Contents Page Foreword.........................................................xi Introduction.....................................................xiii 1 Scope ........................................................ 1 2 Normative references ......................................... 3 3 Definitions, notations, and conventions ...................... 5 3.1 Definitions ................................................ 5 3.1.1Definitions taken from ISO/IEC 10646 ....................... 5 3.1.2Definitions taken from ISO 8601 ............................ 5 3.1.3Definitions provided in this International Standard ........ 5 3.2 Notation ................................................... 7 3.3 Conventions ................................................ 9 3.3.1Informative elements ....................................... 9 3.3.2Specification of syntactic elements ........................ 9 3.3.3Specification of the Information Schema ....................10 3.3.4Use of terms ...............................................10 3.3.4Exceptions .................................................10 3.3.4Syntactic containment ......................................11 3.3.4Terms denoting rule requirements ...........................12 3.3.4Rule evaluation order ......................................12 3.3.4Conditional rules ..........................................13 3.3.4Syntactic substitution .....................................13 3.3.4Other terms ................................................14 3.3.5Descriptors ................................................14 3.3.6Index typography ...........................................15 3.4 Object identifier for Database Language SQL ................16 4 Concepts .....................................................19 4.1 Data types .................................................19 4.2 Character strings ..........................................20 4.2.1Character strings and collating sequences ..................20 4.2.2Operations involving character strings .....................22 4.2.2Operators that operate on character strings and return char- acter strings...............................................22 4.2.2Other operators involving character strings ................23 4.2.3Rules determining collating sequence usage .................23 4.3 Bit strings ................................................26 4.3.1Bit string comparison and assignment .......................27 4.3.2Operations involving bit strings ...........................27 4.3.2Operators that operate on bit strings and return bit strings ............................................................27 4.3.2Other operators involving bit strings ......................27 ii Database Language SQL 4.4 Numbers ....................................................27 4.4.1Characteristics of numbers .................................28 4.4.2Operations involving numbers ...............................29 4.5 Datetimes and intervals ....................................29 4.5.1Datetimes ..................................................30 4.5.2Intervals ..................................................32 4.5.3Operations involving datetimes and intervals ...............34 4.6 Type conversions and mixing of data types ..................34 4.7 Domains ....................................................35 4.8 Columns ....................................................36 4.9 Tables .....................................................37 4.10 Integrity constraints ......................................40 4.10.Checking of constraints ....................................41 4.10.Table constraints ..........................................41 4.10.Domain constraints .........................................43 4.10.Assertions .................................................43 4.11 SQL-schemas ................................................44 4.12 Catalogs ...................................................45 4.13 Clusters of catalogs .......................................45 4.14 SQL-data ...................................................45 4.15 SQL-environment ............................................46 4.16 Modules ....................................................46 4.17 Procedures .................................................47 4.18 Parameters .................................................47 4.18.Status parameters ..........................................47 4.18.Data parameters ............................................48 4.18.Indicator parameters .......................................48 4.19 Diagnostics area ...........................................48 4.20 Standard programming languages .............................49 4.21 Cursors ....................................................49 4.22 SQL-statements .............................................51 4.22.Classes of SQL-statements ..................................51 4.22.SQL-statements classified by function ......................52 4.22.Embeddable SQL-statements ..................................55 4.22.Preparable and immediately executable SQL-statements .......56 4.22.Directly executable SQL-statements .........................58 4.22.SQL-statements and transaction states ......................59 4.23 Embedded syntax ............................................61 4.24 SQL dynamic statements .....................................61 4.25 Direct invocation of SQL ...................................64 4.26 Privileges .................................................64 4.27 SQL-agents .................................................66 4.28 SQL-transactions ...........................................67 4.29 SQL-connections ............................................70 4.30 SQL-sessions ...............................................72 Table of Contents iii 4.31 Client-server operation ....................................74 4.32 Information Schema .........................................75 4.33 Leveling ...................................................75 4.34 SQL Flagger ................................................76 5 Lexical elements .............................................79 5.1 ...................................79 5.2 and ....................................82 5.3 ..................................................89 5.4 Names and identifiers ......................................98 6 Scalar expressions ...........................................107 6.1 ................................................107 6.2 and ...........114 6.3 ..........................................118 6.4 .........................................121 6.5 ...............................124 6.6 ...................................128 6.7 ....................................132 6.8 ..................................139 6.9 ..........................................141 6.10 .......................................144 6.11 .........................................155 6.12 .................................157 6.13 ..................................160 6.14 ................................165 6.15 ................................168 7 Query expressions ............................................173 7.1 ....................................173 7.2
..................................176 7.3
.........................................177 7.4 ..............................................178 7.5 .............................................180 7.6 .............................................185 7.7 ..........................................187 7.8 ............................................189 7.9 ......................................191 7.10 .........................................196 7.11 , , and
....203 8 Predicates ...................................................205 8.1 ................................................205 8.2 .....................................207 8.3 ........................................211 8.4 .............................................212 iv Database Language SQL 8.5 ...........................................214 8.6 ...........................................218 8.7 ..........................220 8.8 .........................................222 8.9 .........................................223 8.10 ..........................................224 8.11 .......................................227 8.12 .........................................229 9 Data assignment rules ........................................231 9.1 Retrieval assignment .......................................231 9.2 Store assignment ...........................................234 9.3 Set operation result data types ............................237 10 Additional common elements ...................................239 10.1 .......................................239 10.2 ..........................................243 10.3 ...............................................245 10.4 ..............................248 10.5 ...........................................251 10.6 and ...252 11 Schema definition and manipulation ...........................255 11.1 ........................................255 11.2 ....................................258 11.3
.........................................260 11.4 ........................................262 11.5 ...........................................266 11.6
..............................270 11.7 .............................272 11.8 ........................274 11.9 ..............................281 11.10 ....................................283 11.11 ....................................284 11.12 ..................................286 11.13 ................................287 11.14 ...............................288 11.15 ...................................289 11.16 ..........................291 11.17 .........................292 11.18 .....................................294 11.19 ..........................................296 11.20 ......................................300 11.21 ........................................301 11.22 ...................................304 11.23 ................................305 Table of Contents v 11.24 ...............................306 11.25 .........................307 11.26 ........................308 11.27 ....................................309 11.28 .................................311 11.29 .............................313 11.30 .....................................314 11.31 .................................318 11.32 ...................................320 11.33 ...............................323 11.34 .....................................325 11.35 .................................328 11.36 ..........................................329 11.37 .........................................333 12 Module .......................................................341 12.1 ...................................................341 12.2 .......................................344 12.3 ................................................346 12.4 Calls to a .....................................352 12.5 ..................................368 13 Data manipulation ............................................371 13.1 ...........................................371 13.2 ...........................................375 13.3 ..........................................377 13.4 ..........................................381 13.5
that identifies a view that is defined by a V, then is said to generally contain the contained in V. If contains , then generally contains . If generally contains and generally contains , then generally contains . An instance A1 of directly contains an instance B1 of if A1 contains B1 without an intervening or . Definitions, notations, and conventions 11 X3H2-92-154/DBL CBR-002 3.3 Conventions 3.3.4.3 Terms denoting rule requirements In the Syntax Rules, the term shall defines conditions that are required to be true of syntactically conforming SQL language. When such conditions depend on the contents of the schema, then they are required to be true just before the actions specified by the General Rules are performed. The treatment of language that does not conform to the SQL Formats and Syntax Rules is implementation- dependent. If any condition required by Syntax Rules is not sat- isfied when the evaluation of Access or General Rules is attempted and the implementation is neither processing non-conforming SQL language nor processing conforming SQL language in a non-conforming manner, then an exception condition is raised: syntax error or access rule violation (if this situation occurs during dynamic ex- ecution of an SQL-statement, then the exception that is raised is syntax error or access rule violation in dynamic SQL statement; if the situation occurs during direct invocation of an SQL-statement, then the exception that is raised is syntax error or access rule violation in direct SQL statement). In the Access Rules, the term shall defines conditions that are required to be satisfied for the successful application of the General Rules. If any such condition is not satisfied when the General Rules are applied, then an exception condition is raised: syntax error or access rule violation (if this situation occurs during dynamic execution of an SQL-statement, then the exception that is raised is syntax error or access rule violation in dynamic SQL statement; if the situation occurs during direct invocation of an SQL-statement, then the exception that is raised is syntax error or access rule violation in direct SQL statement). In the Leveling Rules, the term shall defines conditions that are required to be true of SQL language for it to syntactically conform to the specified level of conformance. 3.3.4.4 Rule evaluation order A conforming implementation is not required to perform the exact sequence of actions defined in the General Rules, but shall achieve the same effect on SQL-data and schemas as that sequence. The term effectively is used to emphasize actions whose effect might be achieved in other ways by an implementation. The Syntax Rules and Access Rules for contained syntactic elements are effectively applied at the same time as the Syntax Rules and Access Rules for the containing syntactic elements. The General Rules for contained syntactic elements are effectively applied be- fore the General Rules for the containing syntactic elements. Where the precedence of operators is determined by the Formats of this International Standard or by parentheses, those operators are ef- fectively applied in the order specified by that precedence. Where the precedence is not determined by the Formats or by parentheses, effective evaluation of expressions is generally performed from 12 Database Language SQL X3H2-92-154/DBL CBR-002 3.3 Conventions left to right. However, it is implementation-dependent whether ex- pressions are actually evaluated left to right, particularly when operands or operators might cause conditions to be raised or if the results of the expressions can be determined without completely evaluating all parts of the expression. In general, if some syn- tactic element contains more than one other syntactic element, then the General Rules for contained elements that appear earlier in the production for the containing syntactic element are applied before the General Rules for contained elements that appear later. For example, in the production: ::= the Syntax Rules and Access Rules for , , and are ef- fectively applied simultaneously. The General Rules for are applied before the General Rules for , and the General Rules for are applied after the General Rules for both and . If the result of an expression or search condition can be deter- mined without completely evaluating all parts of the expression or search condition, then the parts of the expression or search condi- tion whose evaluation is not necessary are called the inessential parts. If the Access Rules pertaining to inessential parts are not satisfied, then the syntax error or access rule violation exception condition is raised regardless of whether or not the inessential parts are actually evaluated. If evaluation of the inessential parts would cause an exception condition to be raised, then it is implementation-dependent whether or not that exception condition is raised. 3.3.4.5 Conditional rules Conditional rules are specified with "If" or "Case" conventions. Rules specified with "Case" conventions include a list of con- ditional sub-rules using "If" conventions. The first such "If" sub-rule whose condition is true is the effective sub-rule of the "Case" rule. The last sub-rule of a "Case" rule may specify "Otherwise". Such a sub-rule is the effective sub-rule of the "Case" rule if no preceding "If" sub-rule in the "Case" rule has a true condition. 3.3.4.6 Syntactic substitution In the Syntax and General Rules, the phrase "X is implicit" indi- cates that the Syntax and General Rules are to be interpreted as if the element X had actually been specified. In the Syntax and General Rules, the phrase "the following is implicit: Y" indicates that the Syntax and General Rules are to be interpreted as if a syntactic element containing Y had actually been specified. Definitions, notations, and conventions 13 X3H2-92-154/DBL CBR-002 3.3 Conventions In the Syntax Rules and General Rules, the phrase "former is equiv- alent to latter" indicates that the Syntax Rules and General Rules are to be interpreted as if all instances of former in the element had been instances of latter. If a BNF nonterminal is referenced in a Subclause without speci- fying how it is contained in a BNF production that the Subclause defines, then Case: - If the BNF nonterminal is itself defined in the Subclause, then the reference shall be assumed to be the occurrence of that BNF nonterminal on the left side of the defining production. - Otherwise, the reference shall be assumed to be to a BNF pro- duction in which the particular BNF nonterminal is immediately contained. 3.3.4.7 Other terms Some Syntax Rules define terms, such as T1, to denote named or unnamed tables. Such terms are used as table names or correlation names. Where such a term is used as a correlation name, it does not imply that any new correlation name is actually defined for the denoted table, nor does it affect the scopes of any actual correlation names. An SQL-statement S1 is said to be executed as a direct result of executing an SQL-statement if S1 is the SQL-statement contained in a that has been executed, or if S1 is the value of an referenced by an contained in a that has been executed, or if S1 was the value of the that was associ- ated with an by a and that same is referenced by an contained in a that has been executed. 3.3.5 Descriptors A descriptor is a conceptual structured collection of data that defines the attributes of an instance of an object of a specified type. The concept of descriptor is used in specifying the seman- tics of SQL. It is not necessary that any descriptor exist in any particular form in any database or environment. Some SQL objects cannot exist except in the context of other SQL objects. For example, columns cannot exist except in tables. Those objects are independently described by descriptors, and the de- scriptors of enabling objects (e.g., tables) are said to include the descriptors of enabled objects (e.g., columns or table con- straints). Conversely, the descriptor of an enabled object is said to be included in the descriptor of an enabling object. 14 Database Language SQL X3H2-92-154/DBL CBR-002 3.3 Conventions In other cases, certain SQL objects cannot exist unless some other SQL object exists, even though there is not an inclusion relation- ship. For example, SQL does not permit an assertion to exist if the tables referenced by the assertion do not exist. Therefore, an as- sertion descriptor is dependent on or depends on zero or more table descriptors (equivalently, an assertion is dependent on or depends on zero or more tables). In general, a descriptor D1 can be said to depend on, or be dependent on, some descriptor D2. There are two ways of indicating dependency of one construct on another. In many cases, the descriptor of the dependent construct is said to "include the name of" the construct on which it is de- pendent. In this case "the name of" is to be understood as meaning "sufficient information to identify the descriptor of"; thus an implementor might choose to use a pointer or a concatenation of , , etc. Alternatively, the descrip- tor may be said to include text (e.g., , ). In such cases, whether the implementation includes ac- tual text (with defaults and implications made explicit) or its own style of parse tree is irrelevant; the validity of the descriptor is clearly "dependent on" the existence of descriptors for objects that are referred to in it. The statement that a column "is based on" a domain, is equivalent to a statement that a column "is dependent on" that domain. An attempt to destroy a descriptor may fail if other descriptors are dependent on it, depending on how the destruction is specified. Such an attempt may also fail if the descriptor to be destroyed is included in some other descriptor. Destruction of a descriptor results in the destruction of all descriptors included in it, but has no effect on descriptors on which it is dependent. 3.3.6 Index typography In the Index to this International Standard, the following conven- tions are used: - Index entries appearing in boldface indicate the page where the word, phrase, or BNF nonterminal was defined; - Index entries appearing in italics indicate a page where the BNF nonterminal was used in a Format; and - Index entries appearing in roman type indicate a page where the word, phrase, or BNF nonterminal was used in a heading, Function, Syntax Rule, Access Rule, General Rule, Leveling Rule, Table, or other descriptive text. Definitions, notations, and conventions 15 X3H2-92-154/DBL CBR-002 3.4 Object identifier for Database Language SQL 3.4 Object identifier for Database Language SQL Function The object identifier for Database Language SQL identifies the characteristics of an SQL-implementation to other entities in an open systems environment. Format ::= ::=