RENAME TABLE

RENAME TABLE 语句用于对已有表进行重命名。

语法图

RenameTableStmt

RENAME TABLE - 图1

TableToTable

RENAME TABLE - 图2

  1. RenameTableStmt ::=
  2. 'RENAME' 'TABLE' TableToTable ( ',' TableToTable )*
  3. TableToTable ::=
  4. TableName 'TO' TableName

示例

  1. CREATE TABLE t1 (a int);
  1. Query OK, 0 rows affected (0.12 sec)
  1. SHOW TABLES;
  1. +----------------+
  2. | Tables_in_test |
  3. +----------------+
  4. | t1 |
  5. +----------------+
  6. 1 row in set (0.00 sec)
  1. RENAME TABLE t1 TO t2;
  1. Query OK, 0 rows affected (0.08 sec)
  1. SHOW TABLES;
  1. +----------------+
  2. | Tables_in_test |
  3. +----------------+
  4. | t2 |
  5. +----------------+
  6. 1 row in set (0.00 sec)

MySQL 兼容性

RENAME TABLE 语句与 MySQL 完全兼容。如发现任何兼容性差异,请尝试 TiDB 支持资源

另请参阅