1 USE master; 2 GO 3 DECLARE @SQL VARCHAR(MAX); 4 SET @SQL='' 5 SELECT @[email protected]+'; KILL '+RTRIM(SPID) 6 FROM master..sysprocesses 7 WHERE dbid=DB_ID('数据库名称'); 8 EXEC(@SQL); 9 GO10 ALTER DATABASE 数据库名称 set MULTI_USER
1 USE master; 2 GO 3 DECLARE @SQL VARCHAR(MAX); 4 SET @SQL='' 5 SELECT @[email protected]+'; KILL '+RTRIM(SPID) 6 FROM master..sysprocesses 7 WHERE dbid=DB_ID('数据库名称'); 8 EXEC(@SQL); 9 GO10 ALTER DATABASE 数据库名称 set MULTI_USER