Learn how to use the SQL RENAME TABLE Statement with the explained examples in this tutorial. Change single or multiple table name using SQL RENAME TABLE statement, you have to specify the old and new table name.
You have to use the ALTER table statement inside which you can use the RENAME TABLE statement. If you rename the table name, the columns of the table remain same and will not change until you change them.
Only the table name will change and the number of columns and the data does not change.
How to Use SQL RENAME TABLE Statement to Change Table Name
To use the RENAME statement, you need to specify the old table name and the new table name. Use the meaningful new table name to easily find it from the other tables.
ALTER TABLE Statement to Change the Name
To change the name of the table, you have to use both the ALTER statement and the RENAME statement. Also, specify the name of the old table and the new table names.
Syntax
1 |
ALTER TABLE old_tablename RENAME TO new_tablename |
Change Table Name using SQL RENAME TABLE Statement
You can change the name of the table using the rename statement and the old name and the new name of the table.
Syntax
1 |
RENAME TABLE old_tablename TO new_tablename |
Rename Multiple Tables Name using SQL RENAME TABLE Statement
In addition to all the above, you can change multiple table names by the single syntax. Specify the multiple table names using the TO statement as given below.
Syntax
1 2 3 4 5 |
RENAME TABLE old_tablename1 TO new_tablename1, old_tablename2 TO new_tablename2, old_tablename3 TO new_tablename3, ... old_tablenameN TO new_tablenameN, |
The description of the parameters is given below. However, there are only two parameters and you can easily find the meaning of these parameters.
Parameter use in the syntax
Sr. No. | Parameter Name | Sr. No. |
---|---|---|
1 | old_tablename | Specify the current table name of the table whose name you want to change. |
2 | new_tablename | Enter your new chosen table name to which you want to change the current table name. |
Let’s create examples using the syntax above.
Examples to Use SQL Rename Table Statement
There are two examples given below to understand the renaming of the table. However, you can easily understand the use with just the first example given below.
Example1
1 2 |
ALTER TABLE Employee RENAME TO Company |
The above example changed the name of the table from Employee to Company.
Example2
1 2 |
ALTER TABLE Supplier RENAME TO Industry |
Example3
1 2 3 |
RENAME TABLE Company TO Industry, Person TO Student, Supplier TO Broker |
You must also learn.
Reference