-- Kill the active database connections
-- Note: Uncomment the 'exec'
DECLARE @execSql VARCHAR (1000) = ''
, @databaseName VARCHAR (100) = ''
, @dbid INT = 0
SET @execSql = ''
SET @databaseName = 'MyDB-DNN-TMAR'
SET @dbid = db_id(@databaseName)
IF (ISNULL (@dbid, '') = '') PRINT 'Bad DB Name'
SELECT @execSql = @execSql + 'kill ' + CONVERT (CHAR(10), sp.spid) + '; '
FROM master.dbo.sysprocesses sp
WHERE dbid = @dbid
AND sp.DBID <> 0
AND sp.spid <> @@spid
SELECT @execSql
-- EXEC (@execSql)
GO
-- kill 59
No comments:
Post a Comment