Home » SQL

SQL query to change column name

In this article, we are going to learn about the columns of the table and the process to change the name of the column.
Submitted by Manu Jemini, on March 11, 2018

Somehow all of us end changing the name of one or name column of the table. This may be because of various reasons. So the main point we need to see is the requirement.

You will need two things:

  1. Table Name
  2. Column name

Then simply say to the database that Alter my table by changing the column name which you want to be changed and pass a new name. That’s it.

Table (employee) having three fields and four data in it,

Id		Name		Address

100		Aman		Mumbai
200		Arun		Pune
300		Karan		Delhi

As we can see, our table employee having three columns name id, name, address having three rows of data filled in it. Now, we are going to alter the name of the column (name) to (employeename) and for that, we need to create an alter query with change query in it. Then we take the result set of all the data and display them on the console.

Query:

ALTER TABLE employee 
CHANGE COLUMN 'name' 'employeename' VARCHAR(45) ;

Display table records.

SELECT * FROM employee;

Output:

SQL query to change column name



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.