Syntax in SQL and DB2


SQL: CREATE

In working on project milestone #3 (and in general), be careful to follow SQL syntax exactly. It is just as picky as any programming language, and perhaps is more arcane. For example,

create table books (
isbn varchar(20) not null,
...
primary key (isbn),
foreign key (AuthorID) references authors
on update restrict
on delete cascade,
...
)

Note there are no commas separating the pieces of the FK declaration! The "on update" and "on delete" proceed immediately after. There is a comma at the end of the whole FK declaration if there is another FK declaration or something else to follow.

The general rule of thumb is that commas separate each component such as a column, PK, or FK delaration, but all modifiers, such as a "not null" for a column delaration, follow the declaration directly (no comma separating it from the main).