Click here to Skip to main content
15,883,925 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.
SQL
"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.

Regards,
Ravi Sharma
Posted
Updated 12-Sep-11 1:12am
v2
Comments
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:

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


hope it helps :)
 
Share this answer
 
v2
 
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
 
v2
for example
my Table Name : table_name
Old Column Name : "OldColumn"
New Column Name : "NewColumn"
SQL
EXECUTE sp_rename N'dbo.table_name.OldColumn', N'Tmp_NewColumn', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.table_name.Tmp_NewColumn', N'NewColumn', 'COLUMN' 
GO

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