数据库
首页 > 数据库> > sql删除进程

sql删除进程

作者:互联网

使用一下语句杀掉进程

USE master
go

DECLARE @dbname VARCHAR(200)
SET @dbname = 'xxxx'  --要关闭进程的数据库名

DECLARE @sql NVARCHAR(500)  
DECLARE @spid NVARCHAR(20)

DECLARE #tb CURSOR
FOR
    SELECT  CAST(spid AS VARCHAR(20))
    FROM    master..sysprocesses
    WHERE   dbid = DB_ID(@dbname)
OPEN #tb
FETCH NEXT FROM #tb INTO @spid
WHILE @@fetch_status = 0 
    BEGIN  
        EXEC('kill '+@spid)
        FETCH NEXT FROM #tb INTO @spid
    END  
CLOSE #tb
DEALLOCATE #tb

标签:删除,dbname,FETCH,spid,sql,进程,NEXT,tb,DECLARE
来源: https://www.cnblogs.com/lanheader/p/14154188.html