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,

  1. Open mysql command line by logging to MySQL server.
  2. Switch to specific Database.
  3. Run RENAME SQL Query.
ADVERTISEMENT

Syntax – Rename Table

The syntax to rename a table in MySQL is

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

Tables in MySQL Database

Now run the following command to rename the MySQL table name:

RENAME TABLE students TO pupils;
MySQL rename table

If you query the tables in the database, you will see pupils.

MySQL show renamed table

Now, try changing it back the table name from ‘pupils’ to ‘students’.