Sql Server: How to rename a column
- Posted by Sqltimes
- On August 9, 2014
- 0 Comments
Quick one today:
Sometimes, we need to rename some column names. Surprisingly, there is no intuitive way to rename a column name in Sql Server i.e. ALTER TABLE statement type method. We need to use a system stored procedure called sp_rename.
Example Below:
The sample code below, renames the column ‘PKID’ in ‘dbo.ProductAttribute’ table to ‘ProductAttributesID’.
1
2
3
4
5
|
-- -- Rename Column -- EXEC sp_rename 'dbo.ProductAttributes.PKID' , 'ProductAttributesID' , 'COLUMN' GO |
Hope this helps,
_Sqltimes
0 Comments