diff --git a/dev/reference/sql/statements/create-table-like.md b/dev/reference/sql/statements/create-table-like.md index 18ddf87af90b2..daa0a7aa1b795 100644 --- a/dev/reference/sql/statements/create-table-like.md +++ b/dev/reference/sql/statements/create-table-like.md @@ -1,6 +1,6 @@ --- title: CREATE TABLE LIKE | TiDB SQL Statement Reference -summary: An overview of the usage of CREATE TABLE AS for the TiDB database. +summary: An overview of the usage of CREATE TABLE LIKE for the TiDB database. category: reference --- diff --git a/dev/reference/sql/statements/create-table.md b/dev/reference/sql/statements/create-table.md index 7417e2de0a7c6..d4c17b6e91c64 100644 --- a/dev/reference/sql/statements/create-table.md +++ b/dev/reference/sql/statements/create-table.md @@ -6,7 +6,7 @@ category: reference # CREATE TABLE -This statement creates a new table in the currently selected database. See also `CREATE TABLE AS`, which is documented separately. +This statement creates a new table in the currently selected database. See also `CREATE TABLE LIKE`, which is documented separately. ## Synopsis @@ -54,6 +54,122 @@ This statement creates a new table in the currently selected database. See also ![TableOptionListOpt](/media/sqlgram-dev/TableOptionListOpt.png) +## Syntax + +```sql +CREATE TABLE [IF NOT EXISTS] tbl_name + (create_definition,...) + [table_options] + +CREATE TABLE [IF NOT EXISTS] tbl_name + { LIKE old_tbl_name | (LIKE old_tbl_name) } + +create_definition: + col_name column_definition + | [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,...) + [index_option] ... + | {INDEX|KEY} [index_name] [index_type] (index_col_name,...) + [index_option] ... + | [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY] + [index_name] [index_type] (index_col_name,...) + [index_option] ... + | {FULLTEXT} [INDEX|KEY] [index_name] (index_col_name,...) + [index_option] ... + | [CONSTRAINT [symbol]] FOREIGN KEY + [index_name] (index_col_name,...) reference_definition + +column_definition: + data_type [NOT NULL | NULL] [DEFAULT default_value] + [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY] + [COMMENT 'string'] + [reference_definition] + | data_type [GENERATED ALWAYS] AS (expression) + [VIRTUAL | STORED] [UNIQUE [KEY]] [COMMENT comment] + [NOT NULL | NULL] [[PRIMARY] KEY] + +data_type: + BIT[(length)] + | TINYINT[(length)] [UNSIGNED] [ZEROFILL] + | SMALLINT[(length)] [UNSIGNED] [ZEROFILL] + | MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL] + | INT[(length)] [UNSIGNED] [ZEROFILL] + | INTEGER[(length)] [UNSIGNED] [ZEROFILL] + | BIGINT[(length)] [UNSIGNED] [ZEROFILL] + | REAL[(length,decimals)] [UNSIGNED] [ZEROFILL] + | DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL] + | FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL] + | DECIMAL[(length[,decimals])] [UNSIGNED] [ZEROFILL] + | NUMERIC[(length[,decimals])] [UNSIGNED] [ZEROFILL] + | DATE + | TIME[(fsp)] + | TIMESTAMP[(fsp)] + | DATETIME[(fsp)] + | YEAR + | CHAR[(length)] [BINARY] + [CHARACTER SET charset_name] [COLLATE collation_name] + | VARCHAR(length) [BINARY] + [CHARACTER SET charset_name] [COLLATE collation_name] + | BINARY[(length)] + | VARBINARY(length) + | TINYBLOB + | BLOB + | MEDIUMBLOB + | LONGBLOB + | TINYTEXT [BINARY] + [CHARACTER SET charset_name] [COLLATE collation_name] + | TEXT [BINARY] + [CHARACTER SET charset_name] [COLLATE collation_name] + | MEDIUMTEXT [BINARY] + [CHARACTER SET charset_name] [COLLATE collation_name] + | LONGTEXT [BINARY] + [CHARACTER SET charset_name] [COLLATE collation_name] + | ENUM(value1,value2,value3,...) + [CHARACTER SET charset_name] [COLLATE collation_name] + | SET(value1,value2,value3,...) + [CHARACTER SET charset_name] [COLLATE collation_name] + | JSON + +index_col_name: + col_name [(length)] [ASC | DESC] + +index_type: + USING {BTREE | HASH} + +index_option: + KEY_BLOCK_SIZE [=] value + | index_type + | COMMENT 'string' + +reference_definition: + REFERENCES tbl_name (index_col_name,...) + [MATCH FULL | MATCH PARTIAL | MATCH SIMPLE] + [ON DELETE reference_option] + [ON UPDATE reference_option] + +reference_option: + RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT + +table_options: + table_option [[,] table_option] ... + +table_option: + AUTO_INCREMENT [=] value + | AVG_ROW_LENGTH [=] value + | [DEFAULT] CHARACTER SET [=] charset_name + | CHECKSUM [=] {0 | 1} + | [DEFAULT] COLLATE [=] collation_name + | COMMENT [=] 'string' + | COMPRESSION [=] {'ZLIB'|'LZ4'|'NONE'} + | CONNECTION [=] 'connect_string' + | DELAY_KEY_WRITE [=] {0 | 1} + | ENGINE [=] engine_name + | KEY_BLOCK_SIZE [=] value + | MAX_ROWS [=] value + | MIN_ROWS [=] value + | ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT} + | STATS_PERSISTENT [=] {DEFAULT|0|1} +``` + ## Examples ```sql diff --git a/v2.1/reference/sql/statements/create-table-like.md b/v2.1/reference/sql/statements/create-table-like.md index 8e4fe645b680f..0af805cf3bf3c 100644 --- a/v2.1/reference/sql/statements/create-table-like.md +++ b/v2.1/reference/sql/statements/create-table-like.md @@ -1,6 +1,6 @@ --- title: CREATE TABLE LIKE | TiDB SQL Statement Reference -summary: An overview of the usage of CREATE TABLE AS for the TiDB database. +summary: An overview of the usage of CREATE TABLE LIKE for the TiDB database. category: reference --- diff --git a/v2.1/reference/sql/statements/create-table.md b/v2.1/reference/sql/statements/create-table.md index 4099d6d9bc330..051dd21ebb7ca 100644 --- a/v2.1/reference/sql/statements/create-table.md +++ b/v2.1/reference/sql/statements/create-table.md @@ -6,7 +6,7 @@ category: reference # CREATE TABLE -This statement creates a new table in the currently selected database. See also `CREATE TABLE AS`, which is documented separately. +This statement creates a new table in the currently selected database. See also `CREATE TABLE LIKE`, which is documented separately. ## Synopsis diff --git a/v3.0/reference/sql/statements/create-table-like.md b/v3.0/reference/sql/statements/create-table-like.md index 2a37d9144d768..599a2f295ff29 100644 --- a/v3.0/reference/sql/statements/create-table-like.md +++ b/v3.0/reference/sql/statements/create-table-like.md @@ -1,6 +1,6 @@ --- title: CREATE TABLE LIKE | TiDB SQL Statement Reference -summary: An overview of the usage of CREATE TABLE AS for the TiDB database. +summary: An overview of the usage of CREATE TABLE LIKE for the TiDB database. category: reference --- diff --git a/v3.0/reference/sql/statements/create-table.md b/v3.0/reference/sql/statements/create-table.md index b80fa9ef324fb..39cd460d3c6dd 100644 --- a/v3.0/reference/sql/statements/create-table.md +++ b/v3.0/reference/sql/statements/create-table.md @@ -7,7 +7,7 @@ aliases: ['/docs/sql/ddl/'] # CREATE TABLE -This statement creates a new table in the currently selected database. See also `CREATE TABLE AS`, which is documented separately. +This statement creates a new table in the currently selected database. See also `CREATE TABLE LIKE`, which is documented separately. ## Synopsis