Rename Table

Grammar Description

In MatrixOne, the RENAME TABLE statement is used to change the name of the table. You can change the names of multiple tables at once.

Notes:

  • RENAME TABLE is an atomic operation. If any rename fails, all rename operations will be rolled back.

  • The table cannot be renamed across different databases. If you want to rename a table across a database, you can first copy the table to the target database and then delete the original table

  • Before renaming the table, make sure there are no active transactions or locks that are using the table.

Grammar Structure

> RENAME TABLE
    tbl_name TO new_tbl_name
    [, tbl_name2 TO new_tbl_name2] ...

Example

create table old_table1(n1 int);
create table old_table2(n1 int);
create table old_table3(n1 int);

RENAME TABLE old_table1 TO new_table1;
RENAME TABLE old_table2 TO new_table2,old_table3 TO new_table3;

mysql> show tables;
+--------------------+
| Tables_in_db1 |
+--------------------+
| new_table1 |
| new_table2 |
| new_table3 |
+--------------------+
3 rows in set (0.00 sec)