1 USE MASTER 2 GO 3 4 DECLARE @dbname SYSNAME 5 SET @dbname = 'ReportServer' --这个是要删除的数据库库名 6 7 DECLARE @s NVARCHAR(1000) 8 DECLARE tb CURSOR LOCAL 9 FOR 10 SELECT s = 'kill ' + CAST(spid AS VARCHAR) 11 FROM MASTER..sysprocesses 12 WHERE dbid = DB_ID(@dbname) 13 14 OPEN tb 15 FETCH NEXT FROM tb INTO @s 16 WHILE @@fetch_status = 0 17 BEGIN 18 EXEC (@s) 19 FETCH NEXT FROM tb INTO @s 20 END 21 CLOSE tb 22 DEALLOCATE tb 23 24 EXEC ('drop database [' + @dbname + ']')