in Search

αρχάριος

greek, noun, pron. "archarios" - beginner, learner, neophyte, novice

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):

  1. USE master
  2. ALTER DATABASE Bad_Ass_DB
  3. SET single_user
  4. GO

Now we can rename the Database:

  1. ALTER DATABASE Bad_Ass_DB
  2. MODIFY NAME = Best_Practice_DB
  3. GO

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.

  1. ALTER DATABASE Best_Practice_DB
  2. SET multi_user
  3. GO

-Marlon Ribunal Please Help Me: Here's How <Link>

 kick it on DotNetKicks.com

[As Posted in my other blog http://dbalink.wordpress.com/]

Leave a Comment

(required) 
(optional)
(required) 

Enter the numbers above:
Submit