可以通过下面代码Kill所有连接到某一数据库的所有连接
代码如下:
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
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END