This morning i needed to rename column name and table name itself , so tought to share it on blog.
The script for renaming any column :
sp_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'
The script for renaming any object (table, sp etc) :
sp_RENAME 'OldTableName' , 'NewTableName'
This example renames the customers table to custs.
EXEC sp_rename 'customers', 'custs'
This example renames the contact title column in the customers table to title.
EXEC sp_rename 'customers.[contact title]', 'title', 'COLUMN'
No comments:
Post a Comment