Skip to content

Instantly share code, notes, and snippets.

@sayham-sjb
Created May 8, 2018 15:25
Show Gist options
  • Save sayham-sjb/1371e6660dca8f0713bc5fbae2780203 to your computer and use it in GitHub Desktop.
Save sayham-sjb/1371e6660dca8f0713bc5fbae2780203 to your computer and use it in GitHub Desktop.
Remove Single User Mode #sql
USE master
GO
DECLARE @kill varchar(max) = '';
SELECT @kill = @kill + 'KILL ' + CONVERT(varchar(10), spid) + '; '
FROM master..sysprocesses
WHERE spid > 50 AND dbid = DB_ID('DATABASENAME')
EXEC(@kill);
GO
SET DEADLOCK_PRIORITY HIGH
ALTER DATABASE {DATABASENAME} SET MULTI_USER WITH NO_WAIT
ALTER DATABASE {DATABASENAME} SET MULTI_USER WITH ROLLBACK IMMEDIATE
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment