Table of contents
1.
Introduction
2.
What is SQL?
3.
How to Change Column Name in SQL?
3.1.
Output
4.
Frequently Asked Questions
4.1.
What is MySQL?
4.2.
What are the applications of SQL?
4.3.
What is a relational DBMS?
4.4.
What is Oracle?
4.5.
What is PostgreSQL?
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

How to Change Column Name in SQL?

Author Anusha Raghav
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hello Ninjas, Welcome back! SQL, or Structured Query Language, is a programming language. It was developed by Donald D. Chamberlain, and Raymond F. Boyce. It is a standard easy-to-learn language, as we will explore further in this article.

How To Change Column Name in SQL?

In this article, we will talk about SQL and how to change column name in SQL with an example. Let’s get started right away.    

What is SQL?

SQL (Structured Query Language) is a programming language developed in the 1970s. It stores, access, and modifies data in a relational database to optimize and manage database performance. Sql statements help data analysts and developers to execute queries, access, retrieve, and modify data, and let us update and remove data from databases.

It is a user-friendly language and offers several functions that we can use to perform different operations on our data. The application of SQL is tremendous as it is used in numerous industries, such as social media, healthcare, finance, etc.

What is SQL?

The two main components of a SQL system that we will use in this article are the SQL table and SQL queries
 

  • SQL tables are the fundamental component of a relational database. It consists of various rows and columns. 
     
  • SQL queries or statements are instructions that the DBMS can comprehend, just like how computers understand binary. SQL queries are built using the different elements of SQL languages, such as identifiers and variables. 

How to Change Column Name in SQL?

In SQL, we can change the column name of an existing table in a database using the ALTER TABLE statement. Let us look at the following steps to see how to change the column name in SQL:

  • Select the table in which you have to make the changes. You can follow the given syntax to select your desired table -
     
/*Syntax to select a table in which we have to make the changes to a column*/

select * from  TableName

 

  • Identify the current name of the column and the new name you want to give it.
     
  • Use the ALTER TABLE statement after identifying the exact table and column to rename in the following way -
     
/*Syntax to use the ALTER TABLE statement*/

ALTER TABLE table_name 
CHANGE COLUMN oldcolumn_name to newcolumn_name;


Note that the above syntax is only valid for MySQL and MariaDB database systems. However, for Oracle, PostgreSQL, and also MySQL database systems, we can use the following syntax -  

/*Syntax to use the ALTER TABLE statement*/

ALTER TABLE table_name 
RENAME COLUMN oldcolumn_name to newcolumn_name;

 

Let's understand this through an example. Below is a table named "Shippings," displaying the shipping id, order status, and the number of customers. We wish to change the column name "shipping_id" to "id." 

Table


We will use the alter table column command to make the changes.
 

ALTER TABLE Shippings 
RENAME COLUMN shipping_id to id;
SELECT * FROM Shippings;

Output

Output

Frequently Asked Questions

What is MySQL?

MySQL is an open-source relational DBMS. It is widely used for web-based applications. It supports SQL and supports data storage in the form of tables.

What are the applications of SQL?

SQL has various applications such as web development, social media, finance, healthcare, and business applications.

What is a relational DBMS?

Relational DBMS is the most popular DBMS. In big organizations, it works with large and structured data. It is based on a relational model that classifies the data into tables or relations - for example - Oracle and MySQL.    

What is Oracle?

Oracle is a relational database management system. It is scalable and supports SQL and Oracle's proprietary procedural language. 

What is PostgreSQL?

It is an open-source relational database management system widely used for geospatial applications. It offers features like server-side programming.    

Conclusion

This article discussed SQL and how to change column name in sql with various examples for better understanding. If you want to dig deeper into SQL, here are some related articles - 
 

 

You may refer to our Guided Path on Code Studios to enhance your skill set on DSA and many more. Check out essential interview questions, practice our available mock tests, and more!

Live masterclass