USE master;
GO
DECLARE @SQL VARCHAR(MAX);
SET @SQL=''
SELECT @SQL=@SQL+'; KILL '+RTRIM(SPID)
FROM mastersysprocesses
WHERE dbid=DB_ID('数据库名');
EXEC(@SQL);
GO
ALTER DATABASE 数据库名 SET MULTI_USER;
单用户模式为:SET SINGLE_USER
USE master;
GO
DECLARE @SQL VARCHAR(MAX);
SET @SQL=''
SELECT @SQL=@SQL+'; KILL '+RTRIM(SPID)
FROM mastersysprocesses
WHERE dbid=DB_ID('数据库名');
EXEC(@SQL);
GO
ALTER DATABASE 数据库名 SET MULTI_USER;
单用户模式为:SET SINGLE_USER
转载于:https://www.cnblogs.com/panxiaoming/p/6731206.html