SQL RENAME TABLE: A Complete Guide
SQL RENAME TABLE
In certain cases, users and database administrators wish to rename a table in a SQL database in order to give it a more appropriate name.
The RENAME TABLE and ALTER TABLE statements in Structured Query Language make it simple for any database user to modify the name.
To change the table’s name, use the RENAME TABLE and ALTER TABLE syntax.
Complete Advance AI topics:-Â CLICK HERE
Complete Python Course with Advance topics:-Click here
Syntax of RENAME Statement in SQL
RENAME old_table_name TO new_table_name;
Examples of RENAME Statement in SQL
Here, we’ve used two distinct SQL examples to show you how to use the RENAME statement to modify the name of a SQL table in the database:
Example 1: Renaming the Table Vehicles
Consider the table Vehicles
:
Vehicle_ID | Vehicle_Name | Vehicle_Cost |
---|---|---|
101 | Honda City | 12,00,00 |
102 | Hyundai i20 | 8,40,000 |
103 | Maruti Swift | 7,50,000 |
104 | Kia Seltos | 15,00,000 |
105 | Tata Nexon | 10,00,000 |
Suppose you want to rename the above table to Vehicle_Inventory_2025
. For this, you need to type the following query:
RENAME Vehicles TO Vehicle_Inventory_2025;
After executing this query, the table Vehicles
will be renamed to Vehicle_Inventory_2025
.
Example 2: Renaming the Table Staff
Consider the table Staff
:
Staff_ID | Staff_Name | Staff_Position | Staff_Salary |
---|---|---|---|
201 | Priya | Manager | 50,000 |
202 | Ravi | Clerk | 30,000 |
203 | Asha | Accountant | 40,000 |
204 | Rohit | Supervisor | 35,000 |
205 | Neha | HR Executive | 45,000 |
To rename the above table to Employee_Records
, use the following query:
RENAME Staff TO Employee_Records;
After this query, the table Staff
will be renamed to Employee_Records
.
Syntax of ALTER TABLE Statement in SQL
ALTER TABLE old_table_name RENAME TO new_table_name;
In this syntax, we use the RENAME TO
keyword after specifying the old table name.
Examples of ALTER TABLE Statement in SQL
Below are three examples to demonstrate how to use the ALTER TABLE statement for renaming a table:
Example 1: Renaming the Table Products
Consider the table Products
:
Product_ID | Product_Name | Product_Price |
---|---|---|
301 | Laptop | 60,000 |
302 | Smartphone | 25,000 |
303 | Smartwatch | 10,000 |
304 | Tablet | 15,000 |
305 | Headphones | 5,000 |
To rename the table to Product_Inventory
, use the following query:
ALTER TABLE Products RENAME TO Product_Inventory;
After executing this query, the table Products
will be renamed to Product_Inventory
.
Example 2: Renaming the Table Students
Consider the table Students
:
Student_ID | Student_Name | Student_Grade |
---|---|---|
401 | Abhishek | A |
402 | Sunita | B |
403 | Mohit | A |
404 | Kavya | B+ |
405 | Aryan | A |
Suppose you want to rename this table to Student_Records
. For this, type the following query:
ALTER TABLE Students RENAME TO Student_Records;
After executing this query, the table Students
will be renamed to Student_Records
.
Example 3: Renaming the Table Orders
Consider the table Orders
:
Order_ID | Customer_Name | Order_Total |
---|---|---|
501 | Shreya | 8,000 |
502 | Raj | 10,000 |
503 | Meera | 7,500 |
504 | Karan | 12,000 |
505 | Priyanka | 9,500 |
To rename the table Orders
to Customer_Orders_2025
, use the following query:
ALTER TABLE Orders RENAME TO Customer_Orders_2025;
After this query, the table Orders
will now be renamed to Customer_Orders_2025
.
Conclusion
Renaming tables in SQL is a simple but essential task that ensures your database is clear and intuitive. Using the RENAME TABLE or ALTER TABLE statements, you can keep your database well-organized and relevant.
For more SQL tips and tutorials, visit UpdateGadh, your trusted source for database management guides.
Download New Real Time Projects :-Click here
mysql rename table
rename table name in sql w3schools
sql rename column
sql rename table postgres
rename table name in sql server using query
oracle sql rename table
alter table rename column
rename column name in sql server
sql server rename table
sql rename table name
sql rename table oracle
sql rename table example
Post Comment