Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
i am using SQL Server 2008. I need to rename a column name in a table using SQL.
BookingRefNo to RefNo
Posted

You can use sp_rename for renaming a column/table

Syntax:

EXEC sp_rename 'table_name.oldColumnName', 'newColumnName','objType'

Example:

Create Table Employee(EMP_ID int, EMP_NAME varchar(100))

Select * from Employee

EXEC sp_rename 'Employee.EMP_NAME','EMPLOYEE_NAME','COLUMN'

Select * from Employee

Do let me know if you have any issues.

Regards,
AK
 
Share this answer
 
Rename Column Syntax

SQL
ALTER TABLE table_name
  RENAME COLUMN old_name to new_name;


Execute below script

SQL
ALTER TABLE table_name
  RENAME COLUMN BookingRefNo to RefNo;
 
Share this answer
 
Just Execute it with correct tableName

SQL
EXEC sp_rename 'TableName.BookingRefNo ', 'RefNo ', 'COLUMN'
GO
 
Share this answer
 
sp_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'
 
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