Kill 进程
动态杀各种进程,谨慎操作;事例 status=‘sleeping’
--AUTHOR KiNg
--DATE 2016-05-30
DECLARE @SPID INT
DECLARE @SQL VARCHAR(500)
BEGIN
SELECT @SPID=MAX(SPID) FROM SYS.sysprocesses WHERE SPID<>@@SPID AND STATUS='SLEEPING' AND SPID>50
AND WAITTYPE=0x0000--代表此链接没有等待任何资源
AND WAITTIME=0
--AND last_batch<DATEADD(MINUTE,-60,GETDATE())
--AND login_time<DATEADD(MINUTE,-60,GETDATE())
--AND OPEN_TRAN>0
WHILE @SPID IS NOT NULL
BEGIN
SET @SQL='KILL '+RTRIM(@SPID)+';'
EXEC(@SQL)
SELECT @SPID=MAX(SPID) FROM SYS.sysprocesses WHERE SPID<>@@SPID AND STATUS='SLEEPING' AND SPID>50
AND WAITTYPE=0x0000--代表此链接没有等待任何资源
AND WAITTIME=0
--AND last_batch<DATEADD(MINUTE,-60,GETDATE())
--AND login_time<DATEADD(MINUTE,-60,GETDATE())
--AND OPEN_TRAN>0
END
END