This chapter introduces the data definition statements.
This is the multi-page printable view of this section. Click here to print.
Data Definition Statements
- 1: ALTER TABLE
- 2: CREATE TABLE
- 3: DROP TABLE
1 - ALTER TABLE
ALTER TABLE
can change the schema or options of a table.
ALTER TABLE SCHEMA
HoraeDB current supports ADD COLUMN
to alter table schema.
|
|
It now becomes:
-- DESCRIBE TABLE `t`;
name type is_primary is_nullable is_tag
t timestamp true false false
tsid uint64 true false false
a int false true false
b string false true false
ALTER TABLE OPTIONS
HoraeDB current supports MODIFY SETTING
to alter table schema.
|
|
The SQL above tries to modify the write_buffer_size
of the table, and the table’s option becomes:
|
|
Besides, the ttl
can be altered from 7 days to 10 days by such SQL:
|
|
2 - CREATE TABLE
Basic syntax
Basic syntax:
|
|
Column definition syntax:
|
|
Partition options syntax:
|
|
Table options syntax are key-value pairs. Value should be quoted with quotation marks ('
). E.g.:
|
|
IF NOT EXISTS
Add IF NOT EXISTS
to tell HoraeDB to ignore errors if the table name already exists.
Define Column
A column’s definition should at least contains the name and type parts. All supported types are listed here.
Column is default be nullable. i.e. NULL
keyword is implied. Adding NOT NULL
constrains to make it required.
|
|
A column can be marked as special column with related keyword.
For string tag column, we recommend to define it as dictionary to reduce memory consumption:
|
|
Engine
Specifies which engine this table belongs to. HoraeDB current support Analytic
engine type. This attribute is immutable.
Partition Options
Note: This feature is only supported in distributed version.
|
|
Example below creates a table with 8 partitions, and partitioned by name
:
|
|
3 - DROP TABLE
Basic syntax
Basic syntax:
|
|
Drop Table
removes a specific table. This statement should be used with caution, because it removes both the table definition and table data, and this removal is not recoverable.