Created
February 12, 2019 08:40
-
-
Save phenixita/be5fa8f128f034e6180f6b5e5f9be5ed to your computer and use it in GitHub Desktop.
Drop and create database with kill processes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE master | |
GO | |
-- Creating the ModernApiDB | |
DECLARE @dbname sysname | |
SET @dbname = 'MY_DB' | |
DECLARE @spid int | |
SELECT @spid = min(spid) from master.dbo.sysprocesses where dbid = db_id(@dbname) | |
WHILE @spid IS NOT NULL | |
BEGIN | |
EXECUTE ('KILL ' + @spid) | |
SELECT @spid = min(spid) from master.dbo.sysprocesses where dbid = db_id(@dbname) AND spid > @spid | |
END | |
GO | |
DROP DATABASE MY_DB | |
GO | |
CREATE DATABASE MY_DB | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment