•
This example shows that the values for the IDENTITY column Id_col will always be generated
by the system. The following sequence generator options will take default values because
they are not specified: MINVALUE, MAXVALUE, and NO CYCLE.
CREATE TABLE tbl1 (
Id_col INTEGER UNSIGNED GENERATED ALWAYS AS IDENTITY
Col2 INTEGER NOT NULL, PRIMARY KEY(Id_col)
INSERT INTO tbl1 values (DEFAULT, 10), (DEFAULT, 20), (DEFAULT, 30);
will result in the following rows inserted into table tbl1; (1,10), (3,20), (5,30).
INSERT INTO tbl1 values (15, 10);
will result in an error indicating that you cannot specify a value for the IDENTITY column
defined as GENERATED ALWAYS.
•
This statement fails with an error indicating that the start value must be less than the
MAXVALUE and greater than the MINVALUE.
CREATE TABLE tbl1 (
Id_col INTEGER UNSIGNED GENERATED BY DEFAULT AS IDENTITY
Col2 INTEGER NOT NULL, PRIMARY KEY(Id_col)
•
In this example, none of the sequence generator options are specified; the defaults values
for all options are used.
start value: 0 (zero)
increment: 1
min value: 0 (zero)
max value: 4294967295
NO CYCLE
CREATE TABLE tbl1 (
Id_col INTEGER UNSIGNED GENERATED BY DEFAULT AS IDENTITY NOT NULL,
Col2 INTEGER NOT NULL, PRIMARY KEY(Id_col)
•
This example shows that the IDENTITY column options can be specified in any order.
CREATE TABLE tbl1 (
Id_col INTEGER UNSIGNED GENERATED BY DEFAULT AS IDENTITY
Col2 INTEGER NOT NULL, PRIMARY KEY(Id_col)
•
This statement fails with an error stating that a table can have only one IDENTITY column.
CREATE TABLE T (surrogate_key LARGEINT GENERATED BY
DEFAULT AS IDENTITY NOT NULL PRIMARY KEY,
name CHAR (256) NOT NULL,
order_number LARGEINT GENERATED BY DEFAULT AS
IDENTITY NOT NULL)
HASH PARTITION BY(surrogate_key);
(
START WITH 1
INCREMENT BY 2) NOT NULL,
);
(
START WITH 100
INCREMENT BY 2
MAXVALUE 10
MINVALUE 50) NOT NULL,
);
);
(
START WITH 100
MAXVALUE 1000
INCREMENT BY 2
MINVALUE 50) NOT NULL,
);
CREATE TABLE Statement
91