CREATE TABLE Statement (create_table_statement)

A CREATE TABLE statement (create_table_statement) defines a base table. There are three syntactic options for creating a table.


<create_table_statement> ::=
table_name> (<column_definition>[,<table_description_element>,...])
| CREATE TABLE <table_name> [(<table_description_element>,...)]
    [IGNORE ROLLBACK] [<sample_definition>] AS <
query_expression> [<duplicates_clause> ]
| CREATE TABLE <table_name> LIKE <table_name> [IGNORE ROLLBACK]

<table_description_element> ::=
| <
| <
| <
| <


SQL Tutorial, Tables, Primary Key, Constraints, Foreign Key Dependencies Between Tables, Indexes, Domains


Executing a CREATE TABLE statement causes data that describes the table (known as a base table) to be stored in the database catalog. This data is called metadata.

A CREATE TABLE statement cannot contain more than one key definition (key_definition).

If the name of the schema is not specified in the table name (table_name), the current schema is assumed implicitly. The table name must not be identical to the name of an existing table in the schema.

The current user must have the CREATEIN privilege for the schema specified either implicitly or explicitly in the table name. The current user becomes the owner of the created table. The user obtains the INSERT, UPDATE, DELETE and SELECT privileges for this table. If the table is not a temporary table, the owner is also granted the INDEX, REFERENCES, and ALTER privileges.

See also:

Restrictions for SQL Statements

Schema Assignment of a Table

?     The schema name is specified before the table name: temporary tables are identified by the schema TEMP before their name.
If a table belongs to a schema other than TEMP, the current user must have the CREATEIN privilege for the specified schema.

?     The schema name is not specified: the table belongs to the current schema. This is either the schema that bears the name of the current user or the schema specified in the SET CURRENT SCHEMA statement.

CREATE TABLE … AS <query_expression> …

?     If no QUERY expression (query_expression) is specified, the CREATE TABLE statement must contain at least one column definition (column_definition).

If a query expression is specified, a base table is defined with the same structure as the result table defined by the QUERY expression.
If column definitions are specified, the column definition may only consist of a column name and the number of column definitions must be equal to the number of columns in the result table generated by the QUERY expression.
The data type (data_type) of the ith column in the base table is identical to that of the ith column in the result table generated by the QUERY expression.
The result table may also contain LONG columns.
If no column definitions are specified, the column names of the result table are used.
The rows of the result table are implicitly inserted in the generated base table. The DUPLICATES clausecan be used to determine how key collisions are handled.
The QUERY expression is subject to certain restrictions that also apply to the INSERT statement.

LIKE <table_name>

If LIKE <table_name> is specified, an empty base table is created which, from the point of view of the current user, has the same structure as the source table, that is, it has all the columns with the same column names and definitions as the source table. This view does not necessarily have to be identical to the actual structure of the source table, since the user may not know all the columns because of privilege limitations.

The specified table must be either a base table, a view table, or a synonym. The user must have at least one privilege for this table.

The current user is the owner of the base table.

If all the key columns of the table specified after LIKE are contained in the base table, they form the key columns in this table. Otherwise, the database system implicitly inserts a key column SYSKEY CHAR(8) BYTE which then represents the key for the base table.

DEFAULT specifications or CONSTRAINT definitions for columns that are copied to the base table also apply to the new base table.


IGNORE ROLLBACK is optional and can only be specified for temporary tables. Temporary tables with this characteristic are not affected by the transaction mechanism; in other words, changes affecting these tables are not reversed by rolling back a transaction.

SQL Statements for Changing Table Properties

?     Adding and deleting columns; changing data types; changing the CONSTRAINT definition: ALTER TABLE statement

?     Renaming columns: RENAME COLUMN statement

?     Renaming the table: RENAME TABLE statement