欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

sqlserver下Kill 所有连接到某一数据库的连接

程序员文章站 2023-12-10 15:20:52
复制代码 代码如下:use masterdeclare @spid intdeclare cur cursorfor select spid from sysprocess...
复制代码 代码如下:

use master
declare @spid int
declare cur cursor
for select spid from sysprocesses where dbid = 5
fetch next from cur into @spid
while @@fetch_status = 0
begin
--exec ('kill ' + @spid )
fetch next from cur into @spid
end
close cur
deallocate cur