Home Sql SQL Alter Column Name
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

SQL Alter Column Name

Advertisement
Alter Column Name in SQL is used to change or modify the name of column in a table.

SQL Alter Column Name

     

Alter Column Name in SQL is used to change or modify the name of column in a table.

Understand with Example

The Tutorial explain you a simple example on SQL Alter Column Name. In this Example, create a table 'Stu_Table' using create statement. The insert into help you to add the records into created table 'Stu_Table'. The select statement retain you the records from table 'Stu_Table'. The ALTER  table statement in SQL is used to modify the table 'Stu_Table'.

Create Table Stu_Table

create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), 
Stu_Class  varchar(10) )

Insert data into Stu_Table

insert into Stu_Table (Stu_Id, Stu_Name) values(1,'Komal');
insert into Stu_Table (Stu_Id, Stu_Name) values(2,'Ajay');
insert into Stu_Table (Stu_Id, Stu_Name) values(3,'Rakesh');
insert into Stu_Table (Stu_Id, Stu_Name) values(4,'Bhanu');
insert into Stu_Table (Stu_Id, Stu_Name) values(5,'Santosh');

Stu_Table

+--------+----------+-----------+
| Stu_Id | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1      | Komal    | 10        |
| 2      | Ajay     | 10        |
| 3      | Rakesh   | 10        |
| 4      | Bhanu    | 10        |
| 5      | Santosh  | 10        | 
+--------+----------+-----------+

Syntax

The ALTER  table statement in SQL is used to modify the table 'Stu_Table' and change keyword change the name of field to new  name of field. The syntax used for Alter Table is given below: 

Alter table table_name change old_column_name  new_column_name type size

Query

The Alter Table alter the table 'Stu_Table'. The change keyword change the column name of  Stu_Id to Id in table 'Stu_Table'.

Alter table Stu_Table change Stu_Id Id varchar(10)

Stu_Table

+--------+----------+-----------+
| Id     | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1      | Komal    | 10        |
| 2      | Ajay     | 10        |
| 3      | Rakesh   | 10        |
| 4      | Bhanu    | 10        |
| 5      | Santosh  | 10        | 
+--------+----------+-----------+
Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 20, 2008

Ask Questions?    Discuss: SQL Alter Column Name   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Yogita Saner Patill
July 1, 2011
SQL - Alter Statement

You can change column name as: Alter table Stu_Table Modify Stu_Id Id varchar(10)
gaurav
September 23, 2011
SQL

your command for changing the column name of a table is wrong and not working.....
Ahmad Oriza
October 10, 2011
Thanks

Thank you very much for share
Logesh
October 20, 2011
the query provided is wrong

The query provided is wrong... it should be like Alter Table tab_name Rename Column old_col_nm To new_col_nm;
Madhu
October 21, 2011
problem in using change

Incorrect syntax near 'change'. when i am using alter for changing the coloumn the above problem is reflecting.
manju
October 26, 2011
awesome query

thank u for the queries.
sdfdsdfd
January 17, 2012
there is no CHANGE command in sql :P

there is no CHANGE command in sql :P
pawneshverma
January 18, 2012
We cant change attribute name directly

we can do it by droping that column and then add new column with updated name due to we can loss our data of old previous column . a solution is exists that first we copy that column values into another again when we create new column the we copy that values from there. thaks
dinesh
January 24, 2012
alter the column name

alter table persons modify (area varchar(100));
sag
February 13, 2012
hi

command to change the database name
Subhash Yadav
April 12, 2012
Change Column Name

alter table table_name change old_column_name new_column_name datatype(size); //this command is not working properly in Sql*Plus,i want to change column name so plz tell me what command should be used.
Joseph
May 8, 2012
Change column name

This query is not working.
Bhawna Rawat
May 24, 2012
Wrong query

This query is not working ...giving an error near CHANGE.....so i think we can only change the column name by "sp_rename oldcolumn name new column name"......
B.RAJESH
August 7, 2012
sql error

while i am execute alter table as1 change e_name name varchar2(10) it will be showing error invalid alter option(ORA-01735). what is the solution tell me
Vijayakanth
August 11, 2012
Sql

What is the command to change a column name in a table?
vikash mishra
August 23, 2012
information sql

this site is very good and all information meet in this site thanks
Aftab Alam
September 4, 2012
rename of column is not working

Rename of column is not working, Can u please send me any other query so that it will work. I am using sql server 2005
bhanu
July 27, 2012
change column name .

This query is not working.
DMCA.com