SQL RENAME TABLE

SQL RENAME TABLE: A Complete Guide

SQL RENAME TABLE: A Complete Guide

Interested in above project ,Click Below
WhatsApp
Telegram
LinkedIn

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_IDVehicle_NameVehicle_Cost
101Honda City12,00,00
102Hyundai i208,40,000
103Maruti Swift7,50,000
104Kia Seltos15,00,000
105Tata Nexon10,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_IDStaff_NameStaff_PositionStaff_Salary
201PriyaManager50,000
202RaviClerk30,000
203AshaAccountant40,000
204RohitSupervisor35,000
205NehaHR Executive45,000

To rename the above table to Employee_Records, use the following query:

See also  SQL AND Condition in SQL Queries

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_IDProduct_NameProduct_Price
301Laptop60,000
302Smartphone25,000
303Smartwatch10,000
304Tablet15,000
305Headphones5,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_IDStudent_NameStudent_Grade
401AbhishekA
402SunitaB
403MohitA
404KavyaB+
405AryanA

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_IDCustomer_NameOrder_Total
501Shreya8,000
502Raj10,000
503Meera7,500
504Karan12,000
505Priyanka9,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.

See also  SQL DELETE Statement

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

🎓 Need Complete Final Year Project?

Get Source Code + Report + PPT + Viva Questions (Instant Access)

🛒 Visit UpdateGadh Store →
💬 Chat Now