CREATE TABLE
command is used to create a new empty table, with columns, indexes and constraints, in the current database.
Once created, unless set as NOT READY
, the table’s definition is fixed and cannot be altered, additional indexes cannot be added or removed.
Index and constraint names are auto-generated by Regatta.
Note: If there is UNIQUE
, PRIMARY KEY
or REFERENCES
constraints, then there must be an INDEX
clause following it. Otherwise, there could be either zero or one INDEX
clause. The INDEX
clause must be after all the constraint clauses (if any).
SET READY
SET NOT READY
NOT READY
. At least one column is required in order to set its state to READY
.
table_name
column_name
data_type
NULL
NULL
values. This is the default.
NOT NULL
NULL
values.
DEFAULT default_expr
NULL
. (Note that when the default value is NULL
and NOT NULL
constraint is specified, you cannot insert rows with the DEFAULT
keyword.)
A possible default values are either a literal (e.g, DEFAULT 'my default'
or DEFAULT 1
) or a variable-free expression that returns a single value
(suitable to store in a single table cell) that is being evaluated at the time the row is created (e.g., DEFAULT NOW()
for current date/timestamp (depends on the column data type)). Note that expressions which include other columns in the current table are not allowed.
UNIQUE
UNIQUE
constraint specifies that the column can contain only unique values. The constraint therefore enforces that any two rows in the same table must differ in this column (note that Regatta is case-sensitive) (e.g., ‘Regatta’ <> ’REGATTA’ <> ‘regatta’).
Note: If the UNIQUE
constraint is specified, the NOT NULL
constraint is required.
Unique constraints implicitly create an index on that column, hence the index clause is required.
PRIMARY KEY
PRIMARY KEY
constraint specifies this column can contain only unique, non-NULL values. Only one primary key can be specified for a table. Since PRIMARY KEY
implies UNIQUE
and NOT NULL
– if any of the latter two is specified for the same column, it is ignored (as it is already implied by the PRIMARY KEY
constraint).
Note: PostgreSQL allows specifying the combination of PRIMARY KEY with NULL constraint, but it ignores the latter and requires only non-NULL values. In Regatta, specifying this contradictory combination of constraints results in an error.
REFERENCES reftable [ refcolumn ] [ ON DELETE referential_action ] [ ON UPDATE referential_action ]
PRIMARY KEY
constraint in the referenced table, in
the same database. With this constraint, a value inserted into the referencing column must match a row
in the referenced table. If refcolumn is omitted, the primary key column of the reftable is used.
Reference constraints implicitly create an index on that column, hence the index clause is required.
A foreign key column is allowed to be NULL
. If it is NULL
, the row is not required to have a match in the
referenced table.
Foreign key restrictions:
VARCHAR(200)
column cannot reference a VARCHAR(100)
column.)DELETE
this clause specifies the action to perform when a referenced row in the referenced table is being deleted.
ON UPDATE
this clause specifies the action to perform when a referenced column in the referenced table is being updated to a new value in the referenced column.
Referential_action
RESTRICT
The DELETE/UPDATE
fails if the check identifies that a foreign key constraint is about to be violated.
Updating a referenced column is not allowed, and the explicit RESTRICT
option is supported for compatibility reasons (but that’s also the default behavior).
INDEX index_parameter
REFERENCES
, UNIQUE
or PRIMARY KEY
constraints are specified, and is optional otherwise.
WITH
, are optional for both tables and indexes. Possible storage parameters:
devices
range_separators
devices
parameter) is 1, this parameter shall not be specified or shall be set to an empty list. If the number of devices is more than 1, this parameter is required and the number of values must be one less than the number of devices.
For example:
NULL
.NULL
values are always stored in the beginning of the first range.customers
and set it ready for DML. Set the column c_custkey
as the primary key,
defined with an index, and the c_name
column with the NOT NULL
constraint.
The primary key index is using the device (m1d2) - note that it has only 1 device therefore the
RANGE_SEPARATORS
clause is not needed.
The column c_name
has an index on it with the following devices:
orders
with a foreign key referencing the primary key of the customers
table.
Set the table as NOT READY
for DML, so it can still be modified with the ALTER TABLE command.
The table primary key (o_order_id
) is using an index stored on device m1d2
The o_name
and o_date
columns have a constraint prohibiting NULL values. The o_date
also has a default value of the current date (by using the function NOW()
).
The o_custkey
column is a foreign key to the primary key of table customers
. It has the NOT NULL
constraint, and it must contain values that exist in the primary key (c_custkey
) in the table customers. This foreign key column has an index, stored on the device m1d3
.
The table itself is stored on the device m1d4
.
Create a table with a calculated column:
transactions
. Set the transaction_date
column with the default of setting the current time.
CREATE TABLE
command conforms to the SQL standard, with the following exceptions:
SET READY
| NOT READY
is a Regatta extension.WITH
clause is a Regatta extension; storage parameters are not in the standard.