Skip to content

Instantly share code, notes, and snippets.

@jtanios
Created March 4, 2017 04:36
Show Gist options
  • Save jtanios/2522394b7ec267895aa04a9da002af58 to your computer and use it in GitHub Desktop.
Save jtanios/2522394b7ec267895aa04a9da002af58 to your computer and use it in GitHub Desktop.
-- Shows process IDs using MyDatabase
SELECT SPId FROM master..SysProcesses
WHERE DBId = DB_ID('MyDatabase') AND SPId <> @@SPID
-- Run this for each process ID
KILL <process_id>
-- Take offline
ALTER DATABASE [MyDatabase] SET OFFLINE WITH ROLLBACK IMMEDIATE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment