There are two most important system defined stored procedure we have in sql server i am going to explain these.
As we know stored procedure are of two types:
- System defined stored procedure
- User defined stored procedure
In system define stored procedure we have to main important stored procedure that are:
This is important to know what are the uses of these 2 stored procedure.
Here i am explaining the uses of these two:
Sp_renamedb
This system define stored procedure is used to rename a database.
Example: Rename database from Practice to Practice1
sp_renamedb 'Practice ' , 'Practice1'
sp_renamedb only rename a database.
Sp_rename
This system defined stored procedure is used to rename any object in the sqlserver (Table,column,database,trigger,etc).
Example: rename object 'Practice' to 'Practice1'
sp_rename 'Practice', 'Practice1', 'object';
Here the object may be any thing like(Table,column,database,trigger,etc).
Here is my database Practice1 and having tables chat1.I want to rename both.
For changing the table name
sp_rename 'chat1','chat','object'
For changing the Column name:
Now i want to change my Name column to userName then:
sp_rename 'employee.Name','UserName','Column'
For changing the Trigger name
sp_rename 'tx','mytrigger','object'
changing tx to mytrigger.