Technical Article

Set Database to Single user

,

This command with rollback all transactions immediate and give you exclusive access to the database.

for more information go to http://msdn2.microsoft.com/en-us/library/ms174269.aspx

/* Script to set database to single user mode and close all user connections
  Note that this command will kill all user connections used the RollBack After 
  command to wait for users to log out.
 */Use Master 
go
Alter Database WriteDatabaseNameHere 
Set Single_User With Rollback Immediate
go

---Now let said you want to rename the db
Alter database WriteDatabaseNameHere modify Name = WriteNewDatabaseNameHere
go
--Finally set database back to multi_user mode
Alter Database WriteDatabasenameHere 
set Multi_user
go

Rate

3.2 (5)

You rated this post out of 5. Change rating

Share

Share

Rate

3.2 (5)

You rated this post out of 5. Change rating