Structure of SQL 89

Reserved Words

SQL 89 has a total of 66 reserved words.

ADD DATE INDEX NULL TABLE
ALL DECIMAL INNER ON TIME
ALTER DELETE INSERT OR TIMESTAMP
AND DESC INTEGER ORDER UNIQUE
ASC DISALLOW INTERVAL PRIMARY UPDATE
Avg DISTINCT INTO REAL VALUES
BETWEEN DROP IS REFERENCES Var
BIT FLOAT JOIN RIGHT VarP
BY FOREIGN KEY SELECT WHERE
CHARACTER FROM LEFT SET WITH
COLUMN GROUP LIKE SMALLINT  
CONSTRAINT HAVING Max StDev  
Count IGNORE Min StDevP  
CREATE IN NOT Sum  

Special Symbols

SQL 89 has a total of 14 special symbols.

- ( * / < <> >
!= ) , + <= = >=

Comment

Comment Block

A Comment Block group is starts with a /* and ends when a */ is read. It has the following format:

/* ... */

When the system is reading a Comment Block, text will be analyzed as a series of characters. So, anytime a */ is read, the group will end. This includes cases where the */ is embedded in other lexical structures such as string literals.

No other groups can be nested within this one.

Comment Line

A Comment Line group is starts with a -- and ends when a NewLine is read. It has the following format:

-- ... NewLine

When the system is reading a Comment Line, text will be analyzed as a series of characters. So, anytime a NewLine is read, the group will end. This includes cases where the NewLine is embedded in other lexical structures such as string literals. The NewLine is not considered part of the group.

No other groups can be nested within this one.

Syntax

Query :
  Alter-Stm
  Create-Stm
  Delete-Stm
  Drop-Stm
  Insert-Stm
  Select-Stm
  Update-Stm

Alter-Stm :
  ALTER TABLE Id ADD COLUMN Field-Def-List Constraint-Opt
  ALTER TABLE Id ADD Constraint
  ALTER TABLE Id DROP COLUMN Id
  ALTER TABLE Id DROP CONSTRAINT Id

Create-Stm :
  CREATE Unique INDEX IntegerLiteral ON Id ( Order-List ) With-Clause
  CREATE TABLE Id ( ID-List ) Constraint-Opt

Unique :
  UNIQUE
  null

With-Clause :
  WITH PRIMARY
  WITH DISALLOW NULL
  WITH IGNORE NULL
  null

Field-Def :
  Id Type NOT NULL
  Id Type

Field-Def-List :
  Field-Def , Field-Def-List
  Field-Def

Type :
  BIT
  DATE
  TIME
  TIMESTAMP
  DECIMAL
  REAL
  FLOAT
  SMALLINT
  INTEGER
  INTERVAL
  CHARACTER

Constraint-Opt :
  Constraint
  null

Constraint :
  CONSTRAINT Id Constraint-Type
  CONSTRAINT Id

Constraint-Type :
  PRIMARY KEY ( ID-List )
  UNIQUE ( ID-List )
  NOT NULL ( ID-List )
  FOREIGN KEY ( ID-List ) REFERENCES Id ( ID-List )

Drop-Stm :
  DROP TABLE Id
  DROP INDEX Id ON Id

Insert-Stm :
  INSERT INTO Id ( ID-List ) Select-Stm
  INSERT INTO Id ( ID-List ) VALUES ( Expr-List )

Update-Stm :
  UPDATE Id SET Assign-List Where-Clause

Assign-List :
  Id = Expression , Assign-List
  Id = Expression

Delete-Stm :
  DELETE FROM Id Where-Clause

Select-Stm :
  SELECT Columns Into-Clause From-Clause Where-Clause Group-Clause Having-Clause Order-Clause

Columns :
  Restriction *
  Restriction Column-List

Column-List :
  Column-Item , Column-List
  Column-Item

Column-Item :
  Column-Source
  Column-Source Id

Column-Source :
  Aggregate
  Id

Restriction :
  ALL
  DISTINCT
  null

Aggregate :
  Count ( * )
  Count ( Expression )
  Avg ( Expression )
  Min ( Expression )
  Max ( Expression )
  StDev ( Expression )
  StDevP ( Expression )
  Sum ( Expression )
  Var ( Expression )
  VarP ( Expression )

Into-Clause :
  INTO Id
  null

From-Clause :
  FROM ID-List Join-Chain

Join-Chain :
  Join Join-Chain
  null

Join :
  INNER JOIN ID-List ON Id = Id
  LEFT JOIN ID-List ON Id = Id
  RIGHT JOIN ID-List ON Id = Id
  JOIN ID-List ON Id = Id

Where-Clause :
  WHERE Expression
  null

Group-Clause :
  GROUP BY ID-List
  null

Order-Clause :
  ORDER BY Order-List
  null

Order-List :
  Id Order-Type , Order-List
  Id Order-Type

Order-Type :
  ASC
  DESC
  null

Having-Clause :
  HAVING Expression
  null

Expression :
  And-Exp OR Expression
  And-Exp

And-Exp :
  Not-Exp AND And-Exp
  Not-Exp

Not-Exp :
  NOT Pred-Exp
  Pred-Exp

Pred-Exp :
  Add-Exp BETWEEN Add-Exp AND Add-Exp
  Add-Exp NOT BETWEEN Add-Exp AND Add-Exp
  Value IS NOT NULL
  Value IS NULL
  Add-Exp LIKE StringLiteral
  Add-Exp IN Tuple
  Add-Exp = Add-Exp
  Add-Exp <> Add-Exp
  Add-Exp != Add-Exp
  Add-Exp > Add-Exp
  Add-Exp >= Add-Exp
  Add-Exp < Add-Exp
  Add-Exp <= Add-Exp
  Add-Exp

Add-Exp :
  Add-Exp + Mult-Exp
  Add-Exp - Mult-Exp
  Mult-Exp

Mult-Exp :
  Mult-Exp * Negate-Exp
  Mult-Exp / Negate-Exp
  Negate-Exp

Negate-Exp :
  - Value
  Value

Value :
  Tuple
  Id
  IntegerLiteral
  RealLiteral
  StringLiteral
  NULL

Tuple :
  ( Select-Stm )
  ( Expr-List )

Expr-List :
  Expression , Expr-List
  Expression

ID-List :
  Id-Member , ID-List
  Id-Member

Id-Member :
  Id
  Id Id