A CREATE TABLE statement defines a base table (see
Table).Syntax
<create_table_statement> ::=
CREATE TABLE <table_name> (<column_definition>[,<table_description_element>,...])
[IGNORE ROLLBACK] [<sample_definition>]
| 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> ::= <column_definition> | <constraint_definition> | <referential_constraint_definition> | <key_definition> | <unique_definition>
table_name, sample_definition, query_expression, duplicates_clause, column_definition, constraint_definition, referential_constraint_definition, key_definition, unique_definitionSQL statement for creating a table called
person:CREATE TABLE person (cno FIXED(4), firstname CHAR(7), name CHAR(7), account FIXED(7,2))
This CREATE TABLE statement comprises the keywords CREATE TABLE followed by the table name and (in parentheses) a list of column names, separated by commas. You can also define other criteria, such as a primary key, or referential integrity conditions.
Explanation
Executing a CREATE TABLE statement causes data that describes the table (or base table) to be stored in the catalog. This data is called metadata.
A CREATE TABLE statement can contain a maximum of 1024 column definitions. If a table is defined without a key, the database system creates a key column implicitly. In this case, up to 1023 additional columns can be defined.
A CREATE TABLE statement cannot contain more than one key definition.
The table name must not be identical with the name of an existing table of the current user.
The current user becomes the
owner of the new table. In other words, he or she 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.Owner of a table
QUERY 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
IGNORE ROLLBACK is optional and can only be specified for temporary tables. Temporary tables with this characteristic are not affected by the transaction mechanism; i.e., changes affecting these tables are not reversed by rolling back a transaction.
SQL statements for changing table properties
Adding, deleting columns, changing data types, changing the CONSTRAINT definition
ALTER TABLE statementRenaming columns
RENAME COLUMN statementRenaming tables
RENAME TABLE statement