SQL Tutorial
SQL Database
SQL Table
SQL Select
SQL Order By
SQL Insert
SQL Update
SQL Delete
Difference
SQL Injection
SQL String Functions
Miscl
- SQL Formatter
- SQL group by
- SQL add/drop/update column operation
- SQL CAST Function
- SQL Comments
- SQL CONCAT Function
- CTE (Common Table Expression)SQL
- How to use distinct in SQL?
- Joining Three or More Tables in SQL
- What is Web SQL?
- How to create functions in SQL?
- How to run SQL Script?
- How to Delete Duplicate Rows in SQL?
- Nth Highest salary
- 12 Codd's Rules
- SQL EXCEPT
- Types of SQL JOIN
- Change datatype of column in SQL
- SQL Auto Increment
- SQL Like
- Commit and Rollback in SQL
- SQL Concatenate
- SQL get month from the date
- Savepoint in SQL
- SQL ORDER BY DATE
- TIME Datatype in SQL
- SQL BETWEEN
- CRUD Operations in SQL
- SQL INDEX
- Scalar Functions in SQL
- SET Operators in SQL
- Types of SQL Commands
- TCL Commands in SQL
- SQL Subquery
- SQL View
- Constraints in SQL
- Pattern Matching in SQL
- SQL Date Functions
- DDL Commands in SQL
- DML Commands in SQL
- SQL CASE
- SQL Inner Join
- SQL IN Operator
- Check Constraint in SQL
- SQL CLAUSES
- SQL LOGICAL OPERATORS
- Delete Column from Table
- Add Column in the Table
- Delete one row in SQL
- Change the Column Value
- How to Add Foreign Key in SQL
- Add a Primary Key
- Insert One or More rows
- How to Use LIKE in SQL
- Cursor in SQL
- Difference Between DROP and Truncate
- SQL Comparison Operators
- SQL COUNT WHERE
- SQL SELECT MIN
- SQL Stored Procedure
- SQL SELECT AVG
- SQL SELECT MAX
- SQL ADD COLUMN
- How to use Auto-Increment in SQL
- SQL Languages
- SQL Arithmetic Operators
- How to Use GROUP BY in SQL
- How to Use ORDER BY in SQL
- Trigger in SQL
- What is Race Condition
- SQL COUNT DISTINCT
PL/SQL Tutorial
Sql Interview Question
SQl Quiz
SQL RENAME TABLE
In some situations, database administrators and users want to change the name of the table in the SQL database because they want to give a more relevant name to the table.
Any database user can easily change the name by using the RENAME TABLE and ALTER TABLE statement in Structured Query Language.
The RENAME TABLE and ALTER TABLE syntax help in changing the name of the table.
Syntax of RENAME statement in SQL
Examples of RENAME statement in SQL
Here, we have taken the following two different SQL examples, which will help you how to change the name of the SQL table in the database using RENAME statement:
Example 1: Let's take an example of a table named Cars:
Car Name | Car Color | Car Cost |
---|---|---|
Hyundai Creta | White | 10,85,000 |
Hyundai Venue | White | 9,50,000 |
Hyundai i20 | Red | 9,00,000 |
Kia Sonet | White | 10,00,000 |
Kia Seltos | Black | 8,00,000 |
Swift Dezire | Red | 7,95,000 |
Table: Cars
- Suppose, you want to change the above table name into "Car_2021_Details". For this, you have to type the following RENAME statement in SQL:
-
RENAME Cars To Car_2021_Details ;
- After this statement, the table "Cars" will be changed into table name "Car_2021_Details".
Example 2: Let's take an example of a table named Employee:
Emp_Id | Emp_Name | Emp_Salary | Emp_City |
---|---|---|---|
201 | Abhay | 25000 | Goa |
202 | Ankit | 45000 | Delhi |
203 | Bheem | 30000 | Goa |
204 | Ram | 29000 | Goa |
205 | Sumit | 40000 | Delhi |
Table: Employee
- Suppose, you want to change the name of the above table into the "Coding_Employees". For this, you have to type the following RENAME statement in SQL:
-
RENAME Employee To Coding_Employees ;
- After this statement, the table "Employee" will be changed into the table name "Coding_Employees".
Syntax of ALTER TABLE statement in SQL
In the Syntax, we have to specify the RENAME TO keyword after the old name of the table.
Examples of ALTER TABLE statement in SQL
Here, we have taken the following three different SQL examples, which will help you how to change the name of the table in the SQL database using ALTER TABLE statement:
Example 1: Let's take an example of a table named Bikes:
Bike_Name | Bike_Color | Bike_Cost |
---|---|---|
KTM DUKE | Black | 185,000 |
Royal Enfield | Black | NULL |
Pulsar | Red | 90,0000 |
Apache | White | NULL |
Livo | Black | 80,000 |
KTM RC | Red | 195,000 |
Table : Bikes
-
Suppose, you want to change the name of the above table into "Bikes_Details" using ALTER TABLE statement. For this, you have to type the following query in SQL:
-
ALTER TABLE Bikes RENAME TO Bikes_Details ;
After this statement, the table "Bikes" will be changed into the table name "Bikes_Details".
Example 2: Let's take an example of a table named Student:
Stu_ID | Stu_Name | Stu_Marks |
---|---|---|
1001 | Abhay | 85 |
1002 | Ankit | 75 |
1003 | Bheem | 60 |
1004 | Ram | 79 |
1005 | Sumit | 80 |
Table : Student
- Suppose, you want to change the name of the above table into "MCA_Student_Details" using ALTER TABLE statement. For this, you have to type the following query in SQL:
-
ALTER TABLE Student RENAME TO MCA_Student_Details ;
After this statement, the table "Student" will be changed into table name "MCA_Student_Details".
Example 3: Let's take an example of a table named Employee:
Emp_Id | Emp_Name | Emp_Salary | Emp_City |
---|---|---|---|
201 | Abhay | 25000 | Goa |
202 | Ankit | 45000 | Delhi |
203 | Bheem | 30000 | Goa |
204 | Ram | 29000 | Goa |
205 | Sumit | 40000 | Delhi |
Table: Employee
- Suppose, you want to change the name of the above table into the "Coding_Employees" using an ALTER TABLE statement. For this, you have to type the following query in SQL:
-
ALTER TABLE Employee RENAME To Coding_Employees ;
After this statement, the table "Employee" will be changed into the table name "Coding_Employees".