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

猜你喜欢

转载自www.cnblogs.com/csl0910/p/10045829.html
今日推荐