Tuesday 29 October 2013

Script to Re-name a column name in SQL Server:

We can rename the column name in SQL Server by executing the inbuilt procedure sp_RENAME  by giving 3 parameters

1) Table with ColumnName_old
2) Table with ColumnName_new
3) Object we are changing, in this case it is COLUMN

All the above 3 must be enclosed in single quotes as there are string parameters to the calling procedure.

Syntax:

sp_RENAME '[SchemaName].[TableName].[ColumnName_Old]' , '[ColumnName_New]', 'COLUMN';


Example:

In the above screen I am going to rename the column using system built-in procedure
The column has been successfully re-named.

Hope the above post is helpful.

Cheers,
Anilkumar P