Monday, March 10, 2008

How To Rename Column In Sql Server

Syntax:
sp_rename [ @objname = ] 'object_name' ,
                   [ @newname = ] 'new_name' ,
                   [ @objtype = ] 'object_type' ]
  
sp_rename
          Changes the name of a user-created object

'object_name'  
          Table ,View,column.

'new_name'
          New name which have to be replaced the old name.

[@objtype =] 'object_type'
         Specifying it's belong to which type like 
Column, Index etc.

Example:

use pubs

SP_RENAME
'DISCOUNTS.stor_id', 'STORID','COLUMN'

In this example Discounts is table name, stor_id is old_columnname, storid in new_columnname, column is an object type.

No comments: