Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements >

CREATE TABLE

Use the CREATE TABLE statement to create a new permanent table in the current database, to place data-integrity constraints on columns, to designate where the table is stored, to define a fragmentation strategy, to indicate the size of its initial and subsequent extents, and to specify how to lock the new table.

You can use the CREATE TABLE statement to create relational-database tables or to create typed tables (object-relational tables). For information on how to create temporary tables, see CREATE Temporary TABLE .

Syntax

Read syntax diagramSkip visual syntax diagram           .-STANDARD-------------.
>>-CREATE--+-RAW------------------+--TABLE--table--------------->
           |  (1)                 |
           +--------STATIC--------+
           |  (1)                 |
           '--------OPERATIONAL---'
 
>--| Table Definition |----------------------------------------><
 
Table Definition:
 
        .-,--------------------------.
        V                       (2)  |                                                                     (4)
|--+-(----| Column Definition |------+--+------------------------------------------------+--)--| Options |------+--|
   |                                    |    .-,---------------------------------------. |                      |
   |                                    |    V                                  (3)    | |                      |
   |                                    '-,----+-| Multiple-Column Constraint |------+-+-'                      |
   |                                           |                       (2)           |                          |
   |                                           '-| Column Definition |---------------'                          |
   |  (5)    (6)                      (7)                                                                       |
   '---------------| OF TYPE Clause |---------------------------------------------------------------------------'
 
Notes:
  1. Extended Parallel Server only
  2. See page Column Definition
  3. See page Multiple-Column Constraint Format
  4. See page Options Clauses
  5. Informix extension
  6. Dynamic Server only
  7. See page OF TYPE Clause (IDS)
Element Description Restrictions Syntax
table Name that you declare here for the new table Must be unique among the names of tables, synonyms, views, and sequences in the database Identifier, p. Identifier

Usage

The CREATE TABLE statement can include various clauses, some of which are identified in the following list. Clauses whose names are followed by "(IDS)" are not supported by Extended Parallel Server. Similarly, clauses whose names are followed by "(XPS)" are not supported by Dynamic Server.

Clause Page What the Clause Specifies
Logging Options Logging Options Logging characteristics of the new table
Column Definition Column Definition Name and other attributes of an individual column
DEFAULT DEFAULT Clause Default value for an individual column
Single-Column Constraint Single-Column Constraint Format Data-integrity constraints on an individual column
REFERENCES REFERENCES Clause Referential-integrity constraints with other columns
CHECK CHECK Clause Check constraints with other columns
Constraint Definition (IDS) Constraint Definition Name and other attributes of a constraint
Multiple-Column Constraint Multiple-Column Constraint Format Data-integrity constraints on a set of columns
WITH CRDCOLS (IDS) Using the WITH CRCOLS Option (IDS) Two shadow columns for Enterprise Replication
Storage Options Storage Options Attributes of where the table is physically stored
IN Using the IN Clause Storage object to hold the new table (or part of it)
FRAGMENT BY or PARTITION BY FRAGMENT BY Clause Distribution scheme of a fragmented table
WITH ROWIDS (IDS) Using the WITH ROWIDS Option (IDS) Hidden column in a fragmented table
RANGE METHOD (XPS) RANGE Method Clause (XPS) Fragmentation strategy based on column values
PUT (IDS) PUT Clause (IDS) Storage location for BLOB or CLOB column values
EXTENT SIZE EXTENT SIZE Options Size of the first and subsequent extents
USING ACCESS METHOD (IDS) USING Access-Method Clause (IDS) How to access the new table
LOCK MODE LOCK MODE Options Locking granularity of the new table
OF TYPE (IDS) OF TYPE Clause (IDS) Named ROW type of a new typed table
UNDER (IDS) Using the UNDER Clause Supertable of a new subtable in a table hierarchy

When you create a new table, every column must have a data type associated with it. The table name must be unique among all the names of tables, views, sequences, and synonyms within the same database, but the names of columns need only be unique among the column names of the same table.

In an ANSI-compliant database, the combination owner.table must be unique among tables, synonyms, views, and sequence objects within the database.

In DB–Access, using CREATE TABLE outside the CREATE SCHEMA statement generates warnings if you use the -ansi flag or if you set DBANSIWARN.

In ESQL/C, using CREATE TABLE generates warnings if you compile with the -ansi flag or set DBANSIWARN. For information about the DBANSIWARN environment variable, see the IBM Informix Guide to SQL: Reference.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]