CREATE TABLE Description Creates a table definition. A table definition consists of a list of column definitions that make up a table row. c-treeACE SQL provides two forms of the CREATE TABLE statement. The first form explicitly specifies column definitions. The second form, with the AS query_expression clause, implicitly defines the columns using the columns in the query expression. Syntax CREATE TABLE [ owner_name. ] table_name ( column_definition [ , { column_definition | table_constraint } ] … )
[ STORAGE_ATTRIBUTES 'attributes' ] ; [ ( column_name [NULL | NOT NULL], … ) ]
[ STORAGE_ATTRIBUTES 'attributes' ] AS query_expression ;
column_name data_type [ DEFAULT { literal | USER | NULL | UID
| SYSDATE | SYSTIME | SYSTIMESTAMP } ] [ column_constraint [ column_constraint … ] ]
Arguments owner_name Specifies the owner of the table. If the name is different from the user name of the user executing the statement, then the user must have DBA privileges. table_name Names the table definition. c-treeACE SQL defines the table in the database named in the last CONNECT statement. column_name data_type Names a column and associates a data type with it. The column names specified must be different than other column names in the table definition. The data_type must be one of the supported data types described in "Data Types". DEFAULT Specifies an explicit default value for a column. The column takes on the value if an INSERT statement does not include a value for the column. If a column definition omits the DEFAULT clause, the default value is NULL. The DEFAULT clause accepts the following arguments:
column_constraint Specifies a constraint that applies while inserting or updating a value in the associated column. For more information, see "Column Constraints". table_constraint Specifies a constraint that applies while inserting or updating a row in the table. For more information, see "Table Constraints". STORAGE_ATTRIBUTES 'attributes' A quoted string that specifies specific c-treeACE SQL table attributes. To combine STORAGE_ATTRIBUTE options, separate them with a semicolon (;) as shown here: CREATE TABLE small_preimage_table (name CHAR(10), age SMALLINT) STORAGE_ATTRIBUTES 'ENCR=TWF24;PREIMG' c-treeACE SQL supports the following STORAGE_ATTRIBUTES parameters:
AS query_expression Specifies a query expression to use for the data types and contents of the columns for the table. The types and lengths of the columns of the query expression result become the types and lengths of the respective columns in the table created. The rows in the resultant set of the query expression are inserted into the table after creating the table. In this form of the CREATE TABLE statement, column names are optional. If omitted, the names for the table columns are also derived from the query expression. For more information, see "Query Expressions". Examples In the following example, the user issuing the CREATE TABLE statement must have REFERENCES privilege on the column “itemno” of the table “john.item”. CREATE TABLE supplier_item ( supp_no INTEGER NOT NULL PRIMARY KEY, item_no INTEGER NOT NULL REFERENCES john.item (itemno), qty INTEGER ) ; The following CREATE TABLE statement explicitly specifies a table owner, admin: CREATE TABLE admin.account ( account integer, balance money (12), info char (84) ) ; The following example shows the AS query_expression form of CREATE TABLE to create and load a table with a subset of the data in the customer table: CREATE TABLE admin.dealer (name, street, city, state) AS SELECT name, street, city, state FROM customer WHERE customer.state IN ('CA','NY', 'TX') ;
The following example includes a NOT NULL column constraint and DEFAULT clauses for column definitions: CREATE TABLE emp ( empno integer NOT NULL, deptno integer DEFAULT 10, join_date date DEFAULT NULL ) ; Authorization The user executing this statement must have either DBA or RESOURCE privilege. If the CREATE TABLE statement specifies a foreign key that references a table owned by a different user, the user must have the REFERENCES privilege on the corresponding columns of the referenced table. The AS query_expression form of CREATE TABLE requires the user to have select privilege on all the tables and views named in the query expression.
|
|||||||||||||||||||||||