Rename Tables in MySQL

Introduction

Sometimes, you may need to change the name of an existing table in MySQL.

This can happen when:

  • You want a more meaningful name

  • You made a mistake while naming the table

  • You are restructuring your database

MySQL allows you to rename tables using simple commands.


What is Rename Table

Renaming a table means changing its name without affecting the data stored inside it.

All the records, columns, and structure remain the same — only the table name changes.


Method 1: Using RENAME TABLE

The most common way to rename a table is using the RENAME TABLE statement.

Syntax

RENAME TABLE old_table_name TO new_table_name; 

Example

RENAME TABLE Students TO Student_Details; 

This changes the table name from Students to Student_Details.


Method 2: Using ALTER TABLE

You can also rename a table using the ALTER TABLE statement.

Syntax

ALTER TABLE old_table_name RENAME TO new_table_name; 

Example

ALTER TABLE Students RENAME TO Student_Details; 

Difference Between Both Methods

MethodUsage
RENAME TABLEPreferred and faster
ALTER TABLEAlso works, but is less commonly used

Both methods achieve the same result.


Important Points

  • Renaming does not delete or modify data

  • Table relationships (like foreign keys) may need to be updated

  • Queries using the old table name will stop working


Example Scenario

Suppose you created a table:

CREATE TABLE Students (...); 

Later, you want a better name:

RENAME TABLE Students TO Student_Info; 

Now the table is accessed using Student_Info.


Common Mistakes

  • Forgetting the correct old table name

  • Using a name that already exists

  • Not updating queries after renaming

  • Ignoring dependencies like foreign keys


Key Points to Remember

  • Use RENAME TABLE or ALTER TABLE to rename tables

  • Data remains unchanged

  • Update all references to the new table name

  • Prefer RENAME TABLE for simplicity