Click here to Skip to main content
15,917,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Developer,

How to alter the Name of Column in Sql Table.
I want to rename the column of the table.
I use the below quary but its not work.
"Alter table table_name change old_column_name  new_column_name type size"

Its greatful for me if anybody give me correct Query in Sql Database.

Ravi Sharma
Updated 12-Sep-11 1:12am
P.Salini 12-Sep-11 7:15am    
In sqlserver You can directly rename the column by right clicking on it and then select rename.

why you want to do it using query.
Toniyo Jackson 12-Sep-11 7:17am    
The syntax you are using is correct. Post you sql query

Run this script:

EXEC sp_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'

hope it helps :)
Share this answer
Share this answer
Use sp_rename.
Read more about this here[^] or here[^].
Share this answer
Any way this will help you.

Sqlserver has built in Stored Procedure sp_rename to change the column names of the Tables

EXEC sp_rename
@objname = '< Table Name.Old Column Name >',
@newname = '<new column name>',
@objtype = 'COLUMN'
Share this answer
for example
my Table Name : table_name
Old Column Name : "OldColumn"
New Column Name : "NewColumn"
EXECUTE sp_rename N'dbo.table_name.OldColumn', N'Tmp_NewColumn', 'COLUMN' 
EXECUTE sp_rename N'dbo.table_name.Tmp_NewColumn', N'NewColumn', 'COLUMN' 

This code change your column name and remain column values as it is.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900