user3832856
user3832856

Reputation: 183

Why I need to set the database to single_user before renaming it?

ALTER DATABASE A SET SINGLE_USER WITH ROLLBACK IMMEDIATE    
ALTER DATABASE A MODIFY NAME = [B]
ALTER DATABASE B SET MULTI_USER

According the Microsoft documentation, I should set the database to single_user then I rename it. Why is that? If it just a matter of making sure that all connections gets closed, wouldn't this work as well?:

ALTER DATABASE A SET OFFLINE WITH ROLLBACK IMMEDIATE

Upvotes: 3

Views: 41

Answers (1)

Francisco Goldenstein
Francisco Goldenstein

Reputation: 13767

To avoid issues while other users are querying the database. That way, you make it single user and only you can hit it.

Read more about it here: https://learn.microsoft.com/en-us/sql/relational-databases/databases/set-a-database-to-single-user-mode

Upvotes: 4

Related Questions