Skip to content

Instantly share code, notes, and snippets.

@jtanios
Created March 4, 2017 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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