MySQL – Rename Table
You can change the name of a MySQL table to a new one.
In this tutorial, we will learn how to rename table in MySQL.
Steps to Rename MySQL Table
To rename MySQL Table,
- Open mysql command line by logging to MySQL server.
- Switch to specific Database.
- Run RENAME SQL Query.
Syntax – Rename Table
The syntax to rename a table in MySQL is
</>
Copy
RENAME TABLE old_name TO new_name;
Example 1 – Change MySQL Table Name
In this example, we shall use a database named ‘school’ and try to change the name of ‘students’ table to ‘pupils’.
Initially, we have
Now run the following command to rename the MySQL table name:
</>
Copy
RENAME TABLE students TO pupils;
If you query the tables in the database, you will see pupils.
Now, try changing it back the table name from ‘pupils’ to ‘students’.