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:

Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.