sql server 强制关闭连接

USE master;
GO
DECLARE @SQL VARCHAR(MAX);
SET @SQL=''
SELECT @SQL=@SQL+'; KILL '+RTRIM(SPID)
FROM master..sysprocesses
WHERE dbid=DB_ID('数据库名');

-- 更改数据库为多用户访问
EXEC(@SQL);
ALTER DATABASE 数据库名 SET MULTI_USER;

 

 

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

 

posted @ 2018-11-30 18:21  3.25  阅读(2144)  评论(0编辑  收藏  举报