15 June, 2011

SQL: Rename Column or Tables,Use of SP_RENAME

--Rename a Column Name replacing Old_Name

EXEC SP_RENAME 'TABLE_NAME.COLUMN_NAME','COLUMN_NAME','COLUMN'

OR

SP_RENAME 'TABLE_NAME.COLUMN_NAME','COLUMN_NAME','COLUMN'




ALTER TABLE Employee
ALTER COLUMN EMP_NAME VARCHAR(100)



--Renaming a table

EXEC SP_RENAME 'Employee', 'New_employee'

OR

SP_RENAME 'Employee', 'New_employee'




SP_RENAME, Procedure Changes the name of a user-created object in the current database.


Remarks:

Changing any part of an object name can break scripts and stored procedures.
I recommend you do not use this statement to rename stored procedures, triggers,
user-defined functions, or views; instead, drop the object and re-create it with the
new name.

To rename objects, columns, and indexes, requires ALTER permission on the object.
To rename user types, requires CONTROL permission on the type. To rename a database,
requires membership in the sysadmin or dbcreator fixed server roles .



Posted By:- javadevelopersguide
Link: http://javadevelopersguide.blogspot.com

No comments:

Post a Comment