如何删除一个应用数据库的所有进程?
请问:
可以用SQL语句来实现,
删除一个应用数据库的所有进程?
谢谢!
------解决方案--------------------CREATE PROCEDURE usp_sys_killallprocesses AS
DECLARE @SPID INT,
@SQL VARCHAR(20)
DECLARE CURSOR_BLOCKED CURSOR LOCAL
FOR
SELECT SPID FROM MASTER..SYSPROCESSES WITH(NOLOCK) WHERE SPID <> @@spid --不杀掉自己
OPEN CURSOR_BLOCKED
FETCH CURSOR_BLOCKED INTO @SPID
WHILE @@FETCH_STATUS = 0
BEGIN
IF @SPID > 50 --非系统进程
BEGIN
SET @SQL = 'KILL ' + CONVERT(VARCHAR(10),@SPID)
EXECUTE( @SQL )
END
FETCH CURSOR_BLOCKED INTO @SPID
END
CLOSE CURSOR_BLOCKED
DEALLOCATE CURSOR_BLOCKED
GO