Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I am using this query to rename the database:

ALTER DATABASE BOSEVIKRAM MODIFY NAME = [BOSEVIKRAM_Deleted]

But it shows an error when executing:

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?

1 Answer

0 votes
by (40.7k points)

Try to set the database to a single-user mode like this:

ALTER DATABASE dbName

SET SINGLE_USER WITH ROLLBACK IMMEDIATE

Then, you can use to rename the database and to set the database to Multiuser Mode:  

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

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...