use master
declare @spid int ;
declare @ddlstring nvarchar(max);
declare @dbname varchar(200);
set @dbname='数据库名';
declare tmpcur cursor
for select distinct spid as spid from sys.sysprocesses
where dbid=db_id(@dbname) ;
OPEN tmpcur;
fetch tmpcur into @spid ;
while (@@FETCH_STATUS=0)
begin
set @ddlstring=N'Kill '+CONVERT( nvarchar,@spid) ;
execute sp_executesql @ddlstring ;
fetch tmpcur into @spid ;
end ;
close tmpcur ;
deallocate tmpcur ;
转自: https://blog.youkuaiyun.com/u012232730/article/details/78861374
本文介绍了一段SQL脚本,用于在SQL Server中杀死指定数据库的所有活动进程。通过声明变量并使用游标遍历系统表sys.sysprocesses,获取目标数据库的会话ID,然后执行kill命令来终止这些进程。
8238

被折叠的 条评论
为什么被折叠?



