1 USE master; 2 GO 3 DECLARE @SQL VARCHAR(MAX); 4 SET @SQL='' 5 SELECT @SQL=@SQL+'; KILL '+RTRIM(SPID) 6 FROM master..sysprocesses 7 WHERE dbid=DB_ID(
1 USE master; 2 GO 3 DECLARE @SQL VARCHAR(MAX); 4 SET @SQL='' 5 SELECT @SQL=@SQL+'; KILL '+RTRIM(SPID) 6 FROM master..sysprocesses 7 WHERE dbid=DB_ID('資料庫名稱'); 8 EXEC(@SQL); 9 GO 10 ALTER DATABASE 資料庫名稱 set MULTI_USER