You can execute the CREATE TABLE statement to create a mapping table for an existing table or search index. This topic describes how to create a mapping table for an existing table.
Syntax
CREATE TABLE [IF NOT EXISTS] table_name(column_name data_type [NOT NULL | NULL],...
| PRIMARY KEY(key_part[,key_part])
)
ENGINE='tablestore',
ENGINE_ATTRIBUTE='{"consistency": consistency [,"allow_inaccurate_aggregation": allow_inaccurate_aggregation]}';
CREATE TABLE [IF NOT EXISTS] table_name(
column_name data_type PRIMARY KEY,column_name data_type [NOT NULL | NULL],...
)
ENGINE='tablestore',
ENGINE_ATTRIBUTE='{"consistency": consistency [,"allow_inaccurate_aggregation": allow_inaccurate_aggregation]}';
Parameters
Parameter | Required | Description |
---|---|---|
IF NOT EXISTS | No | Specifies whether a success response is returned. If you specify IF NOT EXISTS, a success response is returned regardless of whether the table exists. Otherwise, a success response is returned only when the table does not exist. |
table_name | Yes | The name of the table, which is used to identify the table.
The table name in SQL must be the same as the table name in Tablestore. |
column_name | Yes | The name of the column.
The column name in SQL must be equivalent to the column name in the Tablestore table. For example, if the column name in the Tablestore table is Aa, the column name in SQL must be Aa, AA, aA, or aa. |
data_type | Yes | The data type of the column, such as BIGINT, DOUBLE, or BOOL.
The data type of the column in SQL must match the data type of the column in the Tablestore table. For more information about data type mappings, see Data type mappings. |
NOT NULL | NULL | No | Specifies whether the value of the column can be NULL. Valid values:
|
key_part | Yes | The name of the primary key column. Separate multiple primary key columns with commas
(,).
The name of the primary key column must be included in the column names. |
ENGINE | No | The execution engine that is used when you use the mapping table to query data. Default
value: tablestore. Valid values:
|
ENGINE_ATTRIBUTE | No | The attribute of the execution engine. The value of this parameter is in the JSON
format and includes the following items:
|
Examples
- Create a table named exampletable1. The table contains the id primary key column,
the colvalue attribute column, and the content attribute column. The id primary key
column and colvalue attribute column are of the BIGINT type, and the content attribute
column is of the MEDIUMTEXT type.
CREATE TABLE exampletable1 (id BIGINT PRIMARY KEY, colvalue BIGINT, content MEDIUMTEXT);
- Create a table named exampletable2. The table contains the id primary key column,
the colvalue primary key column, and the content attribute column. The id primary
key column is of the BIGINT type, the colvalue primary key column is of the VARCHAR
type, and the content attribute column is of the MEDIUMTEXT type. The results of queries
that are performed on the table must be in strong consistency mode.
CREATE TABLE exampletable2 (id BIGINT, colvalue VARCHAR(1024), content MEDIUMTEXT, PRIMARY KEY(colvalue, id)) ENGINE_ATTRIBUTE='{"consistency": "strong"}';