一次 Kill 掉多個 SPID

CREATE PROC spKill @DB sysname=",@Login sysname=",@Status varchar(20)=’sleeping’,@Kill bit=0
as
IF @DB=" AND @login="
BEGIN
    PRINT ‘請賦予 @DB 或 @Login’
    RETURN
END
DECLARE @sql VARCHAR(max)="
SELECT @sql=@sql + ‘KILL ‘ + CONVERT(varchar,SPID) + ‘;

FROM master..sysprocesses
WHERE (dbid=DB_ID(@DB) or @DB=") AND (loginame=@Login or @Login=")
AND (status=@Status or @Status=’sleeping’)
AND spid <> @@SPID AND spid>50
PRINT @sql
IF @Kill=1
    EXEC(@sql)

GO

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

%d 位部落客按了讚: