SQL/MX 3.2 Reference Manual (H06.25+, J06.14+)
SQL/MX Statements
HP NonStop SQL/MX Release 3.2 Reference Manual—691117-001
2-129
Examples of CREATE TABLE
NonStop SQL/MX will place the primary partition on $DATA1, the second partition
on $VOL1, the third partition on $VOL2, and the fourth partition on $VOL3.
IDENTITY column examples
This example shows how to create an IDENTITY column for a simple table. In this
example, the column surrogate_key is defined as the IDENTITY column and is
the primary key of the table t_id_S.
CREATE TABLE t_id_S (surrogate_key LARGEINT GENERATED BY
DEFAULT AS IDENTITY NOT NULL,
name CHAR (5) NOT NULL,
primary key(surrogate_key)
)
HASH PARTITION BY(surrogate_key);
This example shows the IDENTITY column id_key as part of the clustering key
(STORE BY clause):
CREATE TABLE t_id (id_key LARGEINT GENERATED BY
DEFAULT AS IDENTITY NOT NULL,
name CHAR (256) NOT NULL,
order_number INT UNSIGNED NOT NULL
)
STORE BY (id_key, order_number);
This example shows the IDENTITY column id_key as the partitioning key:
CREATE TABLE t_id (id_key LARGEINT GENERATED BY
DEFAULT AS IDENTITY NOT NULL,
name CHAR (256) NOT NULL,
order_number INT UNSIGNED NOT NULL
)
STORE BY (id_key, order_number)
HASH PARTITION BY(id_key);
This example shows that the values for the IDENTITY column Id_col will always
be generated by the system. MINVALUE, MAXVALUE, and NO CYCLE will take
default values because they are not specified:
CREATE TABLE tbl1 (
Id_col INTEGER UNSIGNED GENERATED ALWAYS AS IDENTITY
(
START WITH 1
INCREMENT BY 2) NOT NULL,
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);
Note. In SQL/MX, the partitioning key must be a subset of the clustering key. In the case
of a table with a single column clustering key, the partitioning key must be the same as the
clustering key.










