CREATE TABLE LIKE

CREATE TABLE LIKE 语句用于复制已有表的定义,但不复制任何数据。

语法图

CreateTableStmt:

CreateTableStmt

LikeTableWithOrWithoutParen:

LikeTableWithOrWithoutParen

TableName:

TableName

示例

CREATE TABLE t1 (a INT NOT NULL);
Query OK, 0 rows affected (0.13 sec)
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
Query OK, 5 rows affected (0.02 sec) Records: 5 Duplicates: 0 Warnings: 0
SELECT * FROM t1;
+---+ | a | +---+ | 1 | | 2 | | 3 | | 4 | | 5 | +---+ 5 rows in set (0.00 sec)
CREATE TABLE t2 LIKE t1;
Query OK, 0 rows affected (0.10 sec)
SELECT * FROM t2;
Empty set (0.00 sec)

MySQL 兼容性

CREATE TABLE LIKE 语句与 MySQL 完全兼容。如发现任何兼容性差异,请在 GitHub 上提交 issue

另请参阅

下载 PDF
产品
TiDB
TiDB Cloud
© 2024 PingCAP. All Rights Reserved.
Privacy Policy.