Skip to content

Latest commit

 

History

History
68 lines (49 loc) · 1.84 KB

sql-statement-create-table-like.md

File metadata and controls

68 lines (49 loc) · 1.84 KB
title summary aliases
CREATE TABLE LIKE | TiDB SQL Statement Reference
An overview of the usage of CREATE TABLE LIKE for the TiDB database.
/docs/dev/sql-statements/sql-statement-create-table-like/
/docs/dev/reference/sql/statements/create-table-like/

CREATE TABLE LIKE

This statement copies the definition of an existing table, without copying any data.

Synopsis

CreateTableLikeStmt ::=
    'CREATE' OptTemporary 'TABLE' IfNotExists TableName LikeTableWithOrWithoutParen OnCommitOpt

OptTemporary ::=
    ( 'TEMPORARY' | ('GLOBAL' 'TEMPORARY') )?

LikeTableWithOrWithoutParen ::=
    'LIKE' TableName
|   '(' 'LIKE' TableName ')'

OnCommitOpt ::=
    ('ON' 'COMMIT' 'DELETE' 'ROWS')?

Examples

mysql> CREATE TABLE t1 (a INT NOT NULL);
Query OK, 0 rows affected (0.13 sec)

mysql> INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
Query OK, 5 rows affected (0.02 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM t1;
+---+
| a |
+---+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+---+
5 rows in set (0.00 sec)

mysql> CREATE TABLE t2 LIKE t1;
Query OK, 0 rows affected (0.10 sec)

mysql> SELECT * FROM t2;
Empty set (0.00 sec)

Pre-split region

If the table to be copied is defined with the PRE_SPLIT_REGIONS attribute, the table created using the CREATE TABLE LIKE statement inherits this attribute, and the Region on the new table will be split. For details of PRE_SPLIT_REGIONS, see CREATE TABLE Statement.

MySQL compatibility

The CREATE TABLE LIKE statement in TiDB is fully compatible with MySQL. If you find any compatibility differences, report a bug.

See also