How to Rename Column Name in SQL?

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.

→ Explore this Curated Program for You ←

Avatar photo
Great Learning Editorial Team
The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.

Full Stack Software Development Course from UT Austin

Learn full-stack development and build modern web applications through hands-on projects. Earn a certificate from UT Austin to enhance your career in tech.

4.8 ★ Ratings

Course Duration : 28 Weeks

Cloud Computing PG Program by Great Lakes

Enroll in India's top-rated Cloud Program for comprehensive learning. Earn a prestigious certificate and become proficient in 120+ cloud services. Access live mentorship and dedicated career support.

4.62 ★ (2,760 Ratings)

Course Duration : 8 months

Scroll to Top