How to Rename Column Name in SQL?

Learn via video course
FREE
View all courses
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Methods to Rename a Column in SQL

We can use the following methods to rename a column in SQL.

  1. We can change the name of a column by using the ALTER command along with the RENAME COLUMN command.

Syntax:

The above syntax is applicable to MySQL, Oracle, and Postgres SQL.

  1. Another way to rename a column name is by using the CHANGE command along with the ALTER command.

Syntax:

The above command is applicable to MySQL and MariaDB.

  1. ALTER command cannot be used to change the column name while using SQL Server. For SQL Server sp_rename command is used.

Syntax:

Examples of Renaming Column Names in SQL

Let us now look at a few examples:

  1. Using ALTER along with the RENAME command.

Let us consider the following Table Employees_detail:

Emp_IDEmp_nameEmp_genderEmp_age
101Amar RathoreMale27
102Dimple KhannaFemale28
103Mayuri ChatterjiFemale27
104Karthik PadmanMale30
105Aisha KhanFemale29
106DiannaFemale27
107JaspreetMale30

We have to rename the column name Emp_age to age_of_emp.

SQL Query:

Output:

Emp_IDEmp_nameEmp_genderage_of_Emp
101Amar RathoreMale27
102Dimple KhannaFemale28
103Mayuri ChatterjiFemale27
104Karthik PadmanMale30
105Aisha KhanFemale29
106DiannaFemale27
107JaspreetMale30

Hence, we see that the column name Emp_age is now changed to age_of_Emp.

  1. Rename a column using ALTER with the CHANGEcommand.

Let us consider a table faculty.

f_IDf_namef_yoef_age
201Dr. Ajeya Krishna1047
202Dr. Sudhanshu Jha1548
203Dr. Gargi Sen1347
204Dr. Karthik Rao1650
205Dr. Aiman Shadab849
206Dr. M Dsouza1057
207Dr.Rajshekhar1250

We will rename column name f_name to phdf_name.

SQL query

Output:

f_IDphdf_namef_yoef_age
201Dr. Ajeya Krishna1047
202Dr. Sudhanshu Jha1548
203Dr. Gargi Sen1347
204Dr. Karthik Rao1650
205Dr. Aiman Shadab849
206Dr. M Dsouza1057
207Dr.Rajshekhar1250

The column name is changed from f_name to phdf_name.

  1. Example to show rename column name in SQL Server

Let us consider a table product_details:

Prod_IDbrandchocolatesales/day
055NestleMilky Bar10000000
056AmulDark Chocolate500000
057GandourSafari200000
058CadburyDairy Milk1000000
059NestleKitkat500000
060CadburySilk300000
061ParleMelody5000000

We will now rename the column name chocolate to prod_name.

SQL Query:

Output:

Prod_IDbrandprod_namesales/day
055NestleMilky Bar10000000
056AmulDark Chocolate500000
057GandourSafari200000
058CadburyDairy Milk1000000
059NestleKitkat500000
060CadburySilk300000
061ParleMelody5000000

Hence, the column name chocolate is now changed to prod_name.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

Learn more

To learn the fundamentals of SQL to write queries and work progressively using multiple databases in-depth, refer to this article on SQL.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Conclusion

  • We learned the different ways to rename column names in SQL.
  • The most common ways that are supported by MySQL, Oracle, PostgreSQL, and MariaDB are to use the ALTER command using the RENAME command and the ALTER command using the CHANGE COLUMN command.
  • To change a column name in SQL Server sp_rename command is used, and here ALTER command cannot be used.

It's now your turn to play around with SQL queries and try out to rename column names in SQL.

See Also: