How to rename a column in SQL Server | SansSQL

Thursday, December 6, 2012

How to rename a column in SQL Server

Simple way of renaming a column in SQL Server is
  1. Go to the Table Designer 
  2. Modify the column name 
  3. Save the changes

Other way is using the Stored Procedure "sp_rename"

Exec sp_rename [ @objname = ] 'object_name' , [ @newname = ] 'new_name' 
    [ , [ @objtype = ] 'object_type' ]

EXEC sp_rename N'dbo.tbl_Details.MailID', N'e-MailID', 'COLUMN'

When the above command is executed, the column named "MailID" in the table "tbl_Details" will be renamed to "e-MailID"

By using the stored procedure sp_rename, the following object types can be renamed
  1. Column
  2. Database
  3. Index
  4. Object
  5. UserDataType 

No comments:

Post a Comment