代码改变世界

数据库删除

2014-10-24 16:46  gdutzhulm  阅读(130)  评论(0编辑  收藏  举报
DECLARE @SPID VARCHAR(20)
DECLARE #TB CURSOR FAST_FORWARD FOR
SELECT SPID=CAST(SPID AS VARCHAR(20)) FROM MASTER..SYSPROCESSES WHERE DBID=DB_ID(N'Test')
OPEN #TB
FETCH NEXT FROM #TB INTO @SPID
WHILE @@FETCH_STATUS=0
BEGIN
     EXEC('KILL '+@SPID)
     FETCH NEXT FROM #TB INTO @SPID
END
CLOSE #TB
DEALLOCATE #TB
IF EXISTS(SELECT 1 FROM sys.databases WHERE name=N'Test')
DROP DATABASE MIES