This SQL tutorial explains how to use the SQL RENAME Table statement to change the name of a SQL table with syntax and example.
SQL RENAME TABLE statement is used to change the name of an existing table. Sometime, we may not choose the appropriate name for a table initially. But in the later stage, we want to give the more appropriate name to the table. In that case, instead of dropping and recreating the table again with a different name, SQL provides functionality to change the name of the table using the RENAME TABLE command.
SQL RENAME Table Syntax
The basic syntax of SQL RENAME TABLE is as follows.
ALTER TABLE old_table_name RENAME to new_table_name;
- old_table_name: The name of the existing table which needs to be renamed.
- new_table_name: The new name of the table for the existing table.
SQL RENAME Table Example
Let’s check an example of SQL RENAME TABLE.
Suppose, you have an employee table as below.
Now for some reason, you want to change the name of the above employee table to employee_salary.
You can use the following syntax to rename the table name.
ALTER TABLE employee RENAME to employee_salary;
After executing the above statement, the employee table name will be changed to employee_salary.