CREATE TABLE
- Last Updated: March 30, 2020
- 3 minute read
- OpenEdge
- Version 12.2
- Documentation
The CREATE TABLE statement allows you to create a new table in an existing
database by defining its column names and column data types. Optionally, you can include table
and column constraints.
The CREATE TABLE syntax forms are explained below:
- The first syntax form explicitly specifies the definition of a column.
- The second syntax form, with the
ASquery_expression clause, implicitly defines the columns using the columns in a query expression. - The third syntax form defines the new table as a multi-tenant table, and allocates storage area of a database to the tenants.
- The fourth syntax form specifies partition key details along with area definitions.
CREATE TABLE statement
used for partitioned tables is an online operation. For detailed information on using the
CREATE TABLE statement for partitioned tables, see OpenEdge SQL Reference.Syntax
The CREATE TABLE statement uses the following syntax:
|
The following syntax is used to define an LOB column in CREATE TABLE
statement:
|
For details on using the CREATE TABLE
statement to designate objects for buffer pool assignments, including an alternate
buffer pool, see Manage OpenEdge Databases.
For details on using the CREATE TABLE
statement to enable transparent data encryption, see Learn about
Security and Auditing.
Example: CREATE TABLE statement
The following example illustrates a CREATE TABLE statement. The
cust_no column has the column constraint NOT NULL, which
indicates that no row in the customer table is to have a NULL value in the
cust_no column.
|
The CREATE TABLE statement also allows you to specify the
DEFAULT clause along with a column definition. The DEFAULT
clause identifies the default value to be used for a column.
The default clause uses the following syntax:
|
Example: CREATE TABLE statement with DEFAULT clause
The following CREATE TABLE statement shows how to use the
DEFAULT clause. The following example sets a default value of 10 for the
deptno column.
|
For more information on the CREATE TABLE statement and the
DEFAULT clause, see OpenEdge Data Management: SQL Reference.
Example: Creating a multi-tenant table
The following example shows how to create a multi-tenant table that overrides areas of the selected tenant table partition:
|
Example: Creating a multi-tenant table with default areas
The following example shows how to a create multi-tenant table which uses the default area
for all the table partition of a tenant. In this case, the DEFAULT tenant is
allocated no space in the database storage area:
|
Example: Defining areas for a DEFAULT tenant
The following example shows how to create a multi-tenant table which uses the default area
for all areas tenants except the DEFAULT tenant:
|
Example: Creating a partitioned table
The following example illustrates how to partition a table based on customer ID. It specifies the default table area for each partition. Values less than or equal to 1000 will be a part of PARTITION p1, values ranging from 1001 to 2000 will be a part of PARTITION p2, and values ranging from 2001 to 3000 will be a part of PARTITION p3. Using an INSERT statement to insert values greater than or equal to 3000 returns an error.
|
Example: Subpartitioning a table
The following example illustrates subpartitioning and creates LIST-LIST-LIST partitions on the tporder_list table:
|
Example: Creating a table with LOB partitions
The following example illustrates how to create a table with LOB partitions:
|
LOB partitions are created in areas as per the areas specified in the partition definition.
In the above example, for LOB column F2, for partition Pub.tpcustomer_p1, the
LOB partition area is Partn misc lob Area; For the rest of the partitions,
the LOB partition area is Tenant 1 table Area.
AREA phrase is not allowed for LOB columns while creating
partitioned tables and the LOB columns cannot be partition key columns.For more information on the CREATE TABLE
statement, see OpenEdge SQL Reference.