SQL RENAME TABLE

The RENAME TABLE statement in SQL is used to change the name of an existing table. This operation does not alter the table structure or its data, only its name.

Syntax


            RENAME TABLE old_table_name TO new_table_name;
            
- old_table_name: The current name of the table.
- new_table_name: The new name to assign to the table.

Example

Let us rename the Employees table to Staff:

Code Example


-- Rename the Employees Table to Staff
RENAME TABLE Employees TO Staff;

-- Verify the Renamed Table
SHOW TABLES;
                

Output

-- Before RENAME:
Tables_in_db_name
Employees

-- After RENAME:
Tables_in_db_name
Staff

Explanation

- The RENAME TABLE command changes the table name from Employees to Staff.
- The SHOW TABLES command verifies that the table name has been updated.

Points to Remember

- Ensure that no active queries are dependent on the old table name.
- Use meaningful table names to make database management easier.