Column attributes 

A column_definition can contain the column name and column attributes.

Syntax

<column_attributes> ::= [<key_or_not_null_spec>] [<default_spec>] [UNIQUE] [<constraint_definition>]
[REFERENCES <referenced_table> [(<referenced_column>)] [<delete_rule>]]

<key_or_not_null_spec> ::= [PRIMARY] KEY | NOT NULL [WITH DEFAULT]

default_spec, constraint_definition, delete_rule

referenced_table
referenced_column

referenced table
referenced column

Explanation

The [PRIMARY] KEY and UNIQUE column attributes must not be used together in a column definition.

If the [PRIMARY] KEY column attribute is specified, the CREATE TABLE statement must not contain a key definition.

LONG data type: you may only specify NOT NULL or a DEFAULT specification as a column attribute for LONG columns.

UNIQUE

The UNIQUE column attribute determines the uniqueness of column values (see also CREATE INDEX statement).

KEY

If the KEY column attribute is specified, this column is part of the key of a table and is called the key column. All key columns must be the first columns specified for a table. The order of the key columns is relevant for the SELECT ORDERED statement. The database system ensures that the key values in a table are unique. The sum of the internal lengths of the key columns must not exceed 1024 bytes. The number of key columns in a table must be less than 512. To improve performance, the key should start with key columns which can assume many different values and which are to be used frequently in conditions with the "=" operator.

If a table is defined without a key column, the database system implicitly creates a key column SYSKEY CHAR(8) BYTE. This column is not visible with a SELECT *. However, it can be specified explicitly and has then the same function as a key column. The SYSKEY column can be used to obtain unique keys generated by the database system. The keys are in ascending order, thus reflecting the order of insertion in the table. The key values in the SYSKEY column are only unique within a table; i.e., the SYSKEY column in two different tables may contain the same values. If a unique key is desired across the entire database system, a key column of the data type CHAR(8) BYTE with the DEFAULT specification STAMP can be defined.

NOT NULL

NOT NULL must not be used together with the DEFAULT specification DEFAULT NULL.

NOT NULL WITH DEFAULT defines a default value that is dependent on the data type of the column. NOT NULL WITH DEFAULT must not be used with any of the DEFAULT specifications.

Column data type

DEFAULT value

CHAR(n) ; VARCHAR(n)

' '

CHAR(n) BYTE ; VARCHAR(n) BYTE

X'00'

FIXED(p,s) , INT, SMALLINT, FLOAT(p)

0

DATE

DATE

TIME

TIME

TIMESTAMP

TIMESTAMP

BOOLEAN

FALSE