RENAME TABLE

This statement renames an existing table to a new name.

Synopsis

RenameTableStmt

RENAME TABLE - 图1

TableToTable

RENAME TABLE - 图2

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

Examples

  1. mysql> CREATE TABLE t1 (a int);
  2. Query OK, 0 rows affected (0.12 sec)
  3. mysql> SHOW TABLES;
  4. +----------------+
  5. | Tables_in_test |
  6. +----------------+
  7. | t1 |
  8. +----------------+
  9. 1 row in set (0.00 sec)
  10. mysql> RENAME TABLE t1 TO t2;
  11. Query OK, 0 rows affected (0.08 sec)
  12. mysql> SHOW TABLES;
  13. +----------------+
  14. | Tables_in_test |
  15. +----------------+
  16. | t2 |
  17. +----------------+
  18. 1 row in set (0.00 sec)

MySQL compatibility

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

See also