Vikram Bose Vikram Bose - 2 months ago 18
SQL Question

Error on renaming database in SQL Server 2008 R2

I am using this query to rename the database:

ALTER DATABASE BOSEVIKRAM MODIFY NAME = [BOSEVIKRAM_Deleted]


But it shows an error when excuting:


Msg 5030, Level 16, State 2, Line 1

The database could not be exclusively locked to perform the operation.


Is anything wrong with my query?

Answer

You could try setting the database to single user mode.

http://stackoverflow.com/a/11624/2408095

use master
ALTER DATABASE BOSEVIKRAM SET SINGLE_USER WITH ROLLBACK IMMEDIATE    
ALTER DATABASE BOSEVIKRAM MODIFY NAME = [BOSEVIKRAM_Deleted]
ALTER DATABASE BOSEVIKRAM_Deleted SET MULTI_USER
Comments