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

前端之家收集整理的这篇文章主要介绍了sqlserver下Kill 所有连接到某一数据库的连接前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="71944" class="copybut" id="copybut71944" onclick="doCopy('code71944')"> 代码如下:

<div class="codebody" id="code71944">
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

原文链接:https://www.f2er.com/mssql/64156.html

猜你在找的MsSQL相关文章