It might frequently happen that we see a necessity to change the name of the segment in the data set to fill their need. With the assistance of SQL or Structured Query Language, the Database Administrators store, update, control and recover information in social data sets. Thus, this article lets us comprehend how to rename a column name in SQL.
The accompanying points will be canvassed in this article:
- What is SQL?
- What is RENAME command in SQL?
- How to Rename column name in SQL?
- Rename column name in MS SQL Server
So let us get everything rolling then, at that point,
What is SQL?
SQL, generally known as SEQUEL, is a Structured Query Language utilized for overseeing and getting to data sets. It depends on the English language and is planned in a manner to recover, control, and access the information effortlessly in the event that you wish to find out about the nuts and bolts of SQL top to bottom. In SQL, there are different statements/commands used to control information. One such control, which is very famous in data sets is renaming the column name in SQL.
In this way, let us comprehend how to utilize the RENAME command in SQL.
What is RENAME command in SQL?
This command is utilized to change the name of a column to another column name. Changing the table to another table name is likewise utilized. Allow us to comprehend how to involve this or column in various data sets. Yet, before that, let’s have a look at the shown table and understand by taking it as our example by showcasing the knowledge of renaming commands in SQL.
SID | SName | SUBJECT | ROLL NO. |
1 | RICKY SHARMA | SQL | 2001 |
2 | DAISY SINGH | PYTHON | 3502 |
3 | SAMEER SETH | MACHINE LEARNING | 2503 |
4 | POOJA SHARMA | DEEP LEARNING | 4504 |
5 | NEHA AGARWAL | RPA | 3005 |
How to Rename column name in SQL?
Rename column name in MySQL, MariaDB, Oracle, and PostgreSQL
To rename a column name in MySQL, MariaDB, Oracle, and Postgre SQL, you can follow the below syntax:
Syntax
ALTER TABLE TableName
RENAME COLUMN OldColumnName TO NewColumnName:
Example:
Write a query to rename the column name “SID” to “StudentsID”.
ALTER TABLE Students:
RENAME COLUMN SID TO StudentsID;
On executing the above query, you will see the following output:
StudentsID | SName | SUBJECT | ROLL NO. |
1 | RICKY SHARMA | SQL | 2001 |
2 | DAISY SINGH | PYTHON | 3502 |
3 | SAMEER SETH | MACHINE LEARNING | 2503 |
4 | POOJA SHARMA | DEEP LEARNING | 4504 |
5 | NEHA AGARWAL | RPA | 3005 |
Rename column name in MS SQL Server
The process of renaming column name is MS SQL Server is different when compared to the other databases. In MS SQL Server, you have to use the stored procedure called sp_rename.
Syntax
sp_rename 'TableName.OldColumnName', 'New ColumnName', 'COLUMN';
Example:
sp_rename ‘Students.SID’, ‘StudentsID’, ‘COLUMN’;
Write a query to rename the column name “SID” to “StudentsID”.
The resulting output will be the same as that for the above queries.
With that, we reach a conclusion to this article on Rename column name in SQL. I want to believe that you found this article educational. I want to believe that you comprehended how to utilize the above commands.