You can sue the CREATE TABLE LIKE syntax to replica the schema of an existing table and create a table based on the schema.
Applicable engines and versions
The CREATE TABLE LIKE syntax is applicable only to LindormTable.
The CREATE TABLE LIKE syntax is supported by LindormTable 2.4.2.1 and later versions. For more information about how to view and upgrade the LindormTable version, see Release notes of LindormTable and Upgrade the minor engine version of a Lindorm instance.
Syntax
create_table_statement ::= CREATE TABLE new_table_identifier LIKE old_table_identifier
[ WITH '(' like_option (',' like_option)* ')']
like_option ::= option_identifier '=' string_literal
Parameters
The CREATE TABLE LIKE syntax replicates only the schema but not the data of the original table.
The new table name (new_table_identifier)
The new table name must comply with the following rules:
The name can contain digits, letters, commas (,), hyphens (-), and underscores (_).
The name cannot start with a period (.) or a hyphen (-).
The name must be 1 to 255 characters in length.
The original table name (old_table_identifier)
You can use the DESCRIBE
syntax to view the schema of the original table. For more information, see DESCRIBE/SHOW/USE.
Replication options (like_option)
You can use the WITH
keyword to specify additional replication options.
The following table describes the supported replication options
Option | Type | Description |
COPY_INDEX | STRING | Specifies whether to create a secondary index that is the same as that of the existing table for the new table that you want to create. Valid values:
|
COPY_SPLITKEYS | STRING | Specifies whether to replicate the partition start key of the original table in the new table. Valid values:
|
Examples
In the following examples, the original table is created by executing the following statement:Testable
CREATE TABLE sensor(
p1 INT NOT NULL,
p2 INT NOT NULL,
c1 VARCHAR,
c2 BIGINT,
PRIMARY KEY(p1, p2)
) WITH (SPLITKEYS = '100000,300000,500000,700000,900000');
Replicate the table schema
Create a new table named table2
that has the same schema with the original table named sensor
.
CREATE TABLE table2 LIKE sensor;
Replicate the schema and partition start key of the original table.
CREATE TABLE table2 LIKE sensor WITH (COPY_SPLITKEYS='true');