Renaming Mysql Tables
How to rename a Mysql table?
Explanation
Rename MySQL tables :
The
RENAME statement is used to rename one or more tables in a database.
Syntax :
RENAME TABLE tbl_name TO new_tbl_name
[, tbl_name2 TO new_tbl_name2] ...
The below renaming mysql tables query renames the student table as class table.
Example :
mysql> rename table student to class;
Query OK, 0 rows affected (0.00 sec)
Now we can view the table whether the name is changed by the following query.
If the query renames more than one table, renaming operations are done from left to right.
We can also swap two table names. Let us assume tmp table which does not exists.
RENAME TABLE emp1 TO tmp,
emp2 TO emp1,
tmp TO emp2;
We can also use
RENAME TABLE to move a table from one database to another.
RENAME TABLE current_db.tbl_name TO other_db.tbl_name;