SQL Server 2008杀数据库连接

杀数据库连接:

DECLARE @temp NVARCHAR(20)

DECLARE myCurse CURSOR
FOR
  SELECT  spid
  FROM    sys.sysprocesses
  WHERE   dbid = DB_ID('YourDatabaseName')
OPEN myCurse
FETCH NEXT FROM myCurse INTO @temp
WHILE @@FETCH_STATUS = 0 
  BEGIN
    EXEC ('kill '+@temp)
    FETCH NEXT FROM myCurse INTO @temp
  END
CLOSE myCurse
DEALLOCATE myCurse


版权声明:本文博客原创文章,博客,未经同意,不得转载。

posted @ 2015-07-02 16:48  mfrbuaa  阅读(211)  评论(0编辑  收藏  举报