Switching between multi-user and single-user modes in SQL Server

Posted: (EET/GMT+2)

 

SQL Server is by nature a multi-user system, but sometimes, especially during maintenance and larger change (DDL) operations, you might with to limit temporarily who can access the database. Also, certain database operations, require that the database is set into single-user mode.

To switch between modes, use the following commands:

ALTER DATABASE [MyDb] SET MULTI_USER WITH NO_WAIT

ALTER DATABASE [MyDb] SET SINGLE_USER WITH NO_WAIT

In addition to these two modes, there is a restricted user mode, which allows "db_owner" users to access the database. For more details, see the SET command reference.