Column Attributes (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 |
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. The database system ensures that the key values in a table are unique. 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.
See also:
RestrictionsIf 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 |