SQL-J Language Reference,
Page 16 of 118


[top]
[prev]
[next]
Documentation Top
Global Index
Reference Manual
TOC Index
Grammar index
Developer's Guide
TOC Index
Tuning Cloudscape
TOC Index

CREATE TABLE statement

A CREATE TABLE statement creates a table. Tables contain columns and constraints that specify a column or columns. Columns have a data type and can specify column constraints. (A constraint is a rule to which data must conform.) For information about constraints, see “CONSTRAINT clause”.

You can specify a default value for a column. A default value is the value to be inserted into a column if no other value is specified. If not explicitly specified, the default value of a column is NULL.

NEW: The ability to specify a default for a column is new in Version 3.0.

The SET LOCKING clause allows you to override row-level locking for the specific table, if your system is set for row-level locking. (If your system is set for table-level locking, you cannot change the locking granularity to row-level locking.) To override row-level locking for the specific table, set locking for the table to TABLE. After you create such a table, you can change locking back to ROW with the a SET LOCKING clause in the ALTER TABLE statement.

NEW: The SET LOCKING clause is new in Version 3.0.

You can specify storage properties such as page size for a table with a PROPERTIES clause.

Tables cannot be created in the SYS schema.

Syntax

CREATE TABLE TableName
    ( {ColumnDefinition | Table-Level Constraint}
    [ , {ColumnDefinition | Table-Level Constraint} ] * )
[ PROPERTIES clause ]
[ SET LOCKING = { TABLE | ROW } ]

ColumnDefinition

SimpleColumnName DataType
    [ [ WITH ] DEFAULT { ConstantExpression | NULL }]
    [ Column-Level Constraint ]*

The syntax of DataType is described in “Data Types”.

The syntaxes of Column-Level Constraint and Table-Level Constraint are described in “CONSTRAINT clause”.

Column Defaults

For the definition of a default value, a ConstantExpression is an expression that does not refer to any table. It can include literals, built-in functions such as USER, CURRENT_DATE, CURRENT_TIME, and CURRENT_TIMESTAMP, java method invocations, java field references, and any other expression, as long as it does not refer directly to a table or to a column in a table. (If the default table contains a method call, the method may in fact contain SQL-J statements that refer to tables and columns.) A method call cannot contain dynamic parameters (?).

In a Cloudscape synchronization system, non-literal defaults are re-evaluated at the source if the insert or updated statement is executed within a work unit.

Examples

CREATE TABLE Cities (
    --define a column-level primary key constraint
    city_id int CONSTRAINT CITIES_PK PRIMARY KEY,
    -- City is a class alias
    city SERIALIZE(City),
    country_ISO_code CHAR(2)
        CONSTRAINT countries_fk REFERENCES Countries)
-- set the pageSize and pageReservedSpace for the table
PROPERTIES cloudscape.storage.pageSize=8192,
    cloudscape.storage.pageReservedSpace=10
-- turn off row-level locking for this table; it will
-- be read-only once loaded
SET LOCKING = TABLE
CREATE TABLE HotelAvailability
    (hotel_id INT,
    booking_date DATE,
    rooms_taken INT DEFAULT 0,
    -- the table-level primary key definition allows you to
    -- include two columns in the primary key definition
    PRIMARY KEY (hotel_id, booking_date))
CREATE TABLE CustomizedTours(
    group_id INT PRIMARY KEY,
    customized_tour SERIALIZE(Tour))
PROPERTIES cloudscape.storage.pageSize=16384,
    cloudscape.storage.minimumRecordSize=8192

NOTE: For more examples of CREATE TABLE statements using the various constraints, see “CONSTRAINT clause”.

Interaction with Java Data Types

You can create columns that store Java objects. For more information, see “Java Data Types (User-Defined Data Types)”.

You can store SQL NULL values in Java data type columns (assuming that the columns do not have NOT NULL constraints). (An SQL NULL value is not the same thing as a Java null reference, although they do map to one another.)

Published Tables

When a table is published, it has the same lock granularity at the target as at the source. The SET LOCKING clause of the CREATE TABLE and ALTER TABLE statements is implicitly published to the targets whose publication includes the affected table.

Column defaults are always implicitly published if a column is published. A column in a target cannot have a different default value than the corresponding column in the source.

[top]
[prev]
[next]


Cloudscape Version 3.0
For technical support, go to: www.cloudscape.com and click Support.
Copyright © 1998 and 1999 Cloudscape, Inc. All rights reserved.