Appendix H. SQL Syntax Reference

SQL:2003 syntax uses BNF (Backus-Naur Form) notation to specify the standard syntax for SQL.

Note

The notation is named after John Backus and Peter Naur, who first introduced a formal notation to describe the syntax of a given language.

The notation is quite complicated, so in this book we simplified it by using the most important elements only. In addition, because the syntaxes for our "big three" differ significantly among themselves (and also are different from the SQL:2003 standards), our purpose was to provide as generic a notation as possible that would be applicable to them all. For additional features not mentioned in this appendix, refer to vendor-specific documentation.

The symbols used in our notation are listed in Table H-1 along with their meanings.

Table H.1. Simplified BNF Notation

Symbol

Meaning

< >

Encloses term names.

|

Separates alternatives (exclusive OR)

[ ]

Designates optional term.

{ }

Indicates at least one of the terms is required.

,...

Indicates the term can be, optionally, repeated.

In addition, all SQL keywords are in uppercase letters; everything else is in lowercase.

DDL Statements

This section provides BNF notation for DDL (Data Definition Language) statements.

Tables

The following notations are to create, modify, and drop database tables, respectively:

CREATE TABLE <table name> ( <column name> <datatype> [<column constraint>,...] [DEFAULT <default value>],... [<table constraint>,...] [physical options] ) ALTER TABLE <table name> { <vendor_specific_add_column_clause> ...

Get SQL Bible, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.