zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Sql Server 强制断开数据库已有连接的方法

server数据库方法SQL连接 强制 断开 已有
2023-09-11 14:20:59 时间

用管理员账户sa登陆,然后在master下新建查询:


在查询窗体输入:

declare @i int declare cur cursor for select spid from sysprocesses where db_name(dbid)= '要断开连接的数据库名称' open cur fetch next from cur into @i while @@fetch_status=0 begin exec('kill '+@i) fetch next from cur into @i end close cur deallocate cur