Renaming database and database objects using T-SQL

With increased usage of SQL Server Management Studio for carrying out most of the day to day tasks, performing many activities is easier to learn and to master those steps from the Management Studio.

This is not always a possibility, assume a task needs to be done at certain specific time or after an event / step / process or it may be required to perform something repeatedly for a number of objects, it would be highly diffucult to repeat that task doing it from the Management Studio.

To rename a database, use the system stored procedure SP_RENAMEDB.

Also in the same way, to rename a database object, use the SP_RENAME system stored procedure.

 

Both the stored procedures accept 2 parameters out of which, the first parameter is the current name of the Database / Object and the second parameter is the new name to which it needs to be renamed to. Also find that the values are string values and hence, enclosed in single quotes.

– Bru Medishetty

Leave a Reply