Browse by Domains

How to Rename Column Name in SQL?

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:

  1. What is SQL?
  2. What is RENAME command in SQL?
  3. How to Rename column name in SQL?
  4. 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.

SIDSNameSUBJECTROLL NO.
1RICKY SHARMASQL2001
2DAISY SINGHPYTHON3502
3SAMEER SETHMACHINE LEARNING2503
4POOJA SHARMADEEP LEARNING4504
5NEHA AGARWALRPA 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:

StudentsIDSNameSUBJECTROLL NO.
1RICKY SHARMASQL2001
2DAISY SINGHPYTHON3502
3SAMEER SETHMACHINE LEARNING2503
4POOJA SHARMADEEP LEARNING4504
5NEHA AGARWALRPA 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.

Avatar photo
Great Learning
Great Learning's Blog covers the latest developments and innovations in technology that can be leveraged to build rewarding careers. You'll find career guides, tech tutorials and industry news to keep yourself updated with the fast-changing world of tech and business.

Leave a Comment

Your email address will not be published. Required fields are marked *

Great Learning Free Online Courses
Scroll to Top