How to Rename Table Name in SQL?

Suppose we have two tables in our database named table1 and table2. Although we have an idea about the contents of table1 and table2 but anyone who does not know the internal structure of the database will have a hard time guessing what kind of data both tables have. Thus, it is a requirement to rename these tables.
We can rename table name in SQL by using the following ways::
- RENAME table statement.
- ALTER TABLE statement.
- sp_rename procedure.
RENAME table Statement in SQL
The RENAME TABLE statement can be used to rename table name in SQL. Here we use the RENAME keyword followed by the old name of the table followed by the To keyword followed by the new name of the table.
Syntax
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Example
Imagine we have a table of students containing their name, age, and class. The table would look like the following:
Students Table:
| Name | Age | Class |
|---|---|---|
| Peter | 15 | 10 |
| Bruce | 14 | 9 |
| Tony | 15 | 9 |
| Clark | 16 | 11 |
| Loki | 13 | 8 |
Now imagine this table is named table1. In this example, we will change its name to studentInformation.
ALTER TABLE Statement in SQL
The ALTER TABLE statement is used to rename table name in SQL. Here we use the ALTER TABLE keyword followed by the old name of the table followed by the RENAME TO keyword followed by the new name of the table.
Syntax
Turn Learning into Career Growth
Example
Imagine we have a table of students containing their name, age, and class. The table would look like the following:
Students Table:
| Name | Age | Class |
|---|---|---|
| Peter | 15 | 10 |
| Bruce | 14 | 9 |
| Tony | 15 | 9 |
| Clark | 16 | 11 |
| Loki | 13 | 8 |
Now imagine this table is named table1. In this example, we will change its name to studentInformation.
Renaming a Table in SQL Server (sq_rename in SQL)
The sp_rename is also used to rename table name in SQL. Here we use the sp_rename keyword followed by the old name and the new name of the table separated by a comma.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Syntax
Example
Imagine we have a table of students containing their name, age, and class. The table would look like the following:
Students Table:
| Name | Age | Class |
|---|---|---|
| Peter | 15 | 10 |
| Bruce | 14 | 9 |
| Tony | 15 | 9 |
| Clark | 16 | 11 |
| Loki | 13 | 8 |
Now imagine this table is named table1. In this example, we will change its name to studentInformation.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Conclusion
- SQL offers multiple methods to rename table name in SQL: RENAME table statement, ALTER TABLE statement, and sp_rename procedure.
- These methods provide flexibility in renaming tables according to specific requirements.
- Renaming tables can enhance clarity and organization within a database, improving readability and maintenance.
- Whether using RENAME TABLE, ALTER TABLE, or sp_rename, SQL users have versatile options to manage table names efficiently.