This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am providing different scripts for renaming Database, Table, and Column of SQL Server.
In day to day life, renaming Database or other objects is a common requirement for all database professional.
But as much as possible, we should avoid this practice because stored procedures or functions are using table or column on which you are going to execute rename operation.
During rename operation, you will also get below warning message.
1 |
Caution: Changing any part of an object name could break scripts and stored procedures. |
You can use SP_RENAME to rename different objects.
Script to Rename Databases:
1 2 |
EXEC SP_RENAMEDB 'Old_Database', 'New_Database' GO |
Script to Rename Tables:
1 2 |
EXEC SP_RENAME 'Old_Table','New_Table' GO |
Script to Rename Columns:
1 2 3 4 5 |
EXEC SP_RENAME @ObjName = 'Table_Name.Old_Column' ,@NewName = 'New_Column' ,@ObjType = 'COLUMN' GO |
Leave a Reply