|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Yesterday @ 4:40 AM
Points: 711,
Visits: 212
|
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Saturday, June 15, 2013 7:40 PM
Points: 242,
Visits: 658
|
|
i often use something more simple
DECLARE @TARGET INT WHILE 1=1 BEGIN DECLARE KILLCONS CURSOR LOCAL FAST_FORWARD FOR SELECT SPID FROM MASTER..SYSPROCESSES WHERE DBID = DB_ID('DB NAME') AND SPID >=50 OPEN KILLCONS FETCH NEXT FROM KILLCONS INTO @TARGET WHILE @@FETCH_STATUS = 0 BEGIN EXEC ('KILL '+@TARGET) FETCH NEXT FROM KILLCONS INTO @TARGET END CLOSE KILLCONS DEALLOCATE KILLCONS END the infinite while is to take care of pesky applications that keep reconnecting, so you just manually break the loop when you feel like it
-- Thiago Dantas @DantHimself
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Yesterday @ 4:40 AM
Points: 711,
Visits: 212
|
|
| You're right - this procedure would be much more simple if I used cursors as You did.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, August 23, 2012 10:34 PM
Points: 18,
Visits: 162
|
|
i use this:
ALTER DATABASE Northwind SET SINGLE_USER WITH ROLLBACK IMMEDIATE EXEC sp_dboption 'Northwind', 'single user', 'FALSE'
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, June 14, 2013 3:25 AM
Points: 11,
Visits: 336
|
|
--Kill all users instantly
use master go alter database test set offline with rollback immediate go alter database test set online go
|
|
|
|