How to Read SQL Syntax
We have used the following common variant of BNF notation for the SQL syntax diagrams in this book:
< >
Angle brackets surround the names of syntactic elements. The brackets are not part of the syntax; do not include them in your SQL statement.::=
The definition operator separates the syntactic element being defined from its definition. Read the definition from left to right.[ ]
Square brackets surround optional syntax. You may choose whether or not to omit such syntax when forming an SQL statement. The brackets are not part of the syntax; do not include them in your SQL statement.{ }
Braces surround mandatory syntax groupings. You must include the entire grouping when forming an SQL statement. The braces are not part of the syntax; do not include them in your SQL statement.|
The vertical bar separates groups of syntactic elements. You must choose one of the elements when forming an SQL statement. The vertical bar is not part of the syntax; do not include it in your SQL statement....
An ellipsis following a syntactic element indicates that the syntax is repeatable. You may include the element as often as you wish when forming an SQL statement. The ellipsis is not part of the syntax; do not include it in your SQL statement.
Blank spaces (whether single or multiple spaces and/or line breaks) separate syntactic elements.All other characters in a definition stand for themselves.
We also follow these notation conventions:
- Words written in uppercase letters are SQL <keyword>s. You must write them exactly as shown when forming an SQL statement, except that you have the choice of writing them in either uppercase or lowercase letters.
- Words written in lowercase letters represent syntactic categories. You must replace them with actual <identifier>s or <literal>s when forming an SQL statement.
- Parentheses that appear in a syntax diagram are part of the syntax. You must include them when forming an SQL statement.
Thus, as in the following simplified example of an SQL syntax diagram:
CREATE TABLE <Table name> ( <Column name> {INTEGER | CHARACTER(5)} )
- The words CREATE and TABLE are SQL <keyword>s and must be included, without changes, in a CREATE TABLE statement.
- The words <Table name> and <Column name> are syntactic categories and must be replaced with an actual <Table name> and <Column name>, respectively, in a CREATE TABLE statement. The angle brackets around "Table name" and "Column name" indicate that these terms are defined with a syntax diagram somewhere in this book.
- The parentheses are part of the syntax and must be included, exactly where shown, in a CREATE TABLE statement.
- The braces and vertical bar after the <Column name> indicate that either one of the SQL <keyword>s "INTEGER" or "CHARACTER(5)" must be included, without changes, in a CREATE TABLE statement.
Based on this example, the following two SQL statements are the only valid uses of the syntax:
CREATE TABLE A_Table_Name ( a_column_name INTEGER); CREATE TABLE A_Table_Name ( a_column_name CHARACTER(5));