当前位置 : 主页 > 数据库 > mssql >

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

来源:互联网 收集:自由互联 发布时间:2021-04-05
复制代码 代码如下: 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 @sp
复制代码 代码如下:
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
网友评论