How To: Rename SQL Server 2005 Database Using TSQL
For some reasons, DBA’s need to rename their Databases. One of the reasons might be to comply to Best Practices Policy changes.
Here we are going to rename our Database named “Bad_Ass_DB” into “Best_Practice_DB”. This is how Database renaming with TSQL is done in SQL Server 2005:
First we need to put our Bad_Ass_DB offline or alter it to single-user mode. You cannot rename a database if it is online or in multi-user mode. And prior to that, there should be no active connection to the database (user, application, etc):
Now we can rename the Database:
Then we can set the database back to multi-user mode. Then, real hard work begins: mapping all your codes, processess, applications, web.config, etc to the new name.
ON The News: SQL Server 2008 On Productivity Boosts