Archive

Posts Tagged ‘Alter’

Changing SQL database to single user mode and back to Multi User mode

October 26, 2010 1 comment

It is often necessary to change the database to single user mode, especially if you are a DBA. A simple example would be to change the collation settings or any DB settings. The single user will allow only one  user ( usually DBA) to access the database. Hence it will be easy to make changes without the worry of deadlocks or any other type of contention for DB and also without affecting the users.

It is very easy to change the database to Single user mode; in fact, it is just an execution of the script away. Use the script below to change the mode.

ALTER  DATABASE <<Database Name>>  SET SINGLE_USER  WITH NO_WAIT

The NO_WAIT clause will set it to single user mode as soon as you execute the query.  An alternate to this is by using the system stored procedure sp_dboption

Continue Reading ….