首页 > 数据库 > SQL Server >

SQLServer2008杀死数据库连接

2014-11-12

杀死数据库连接: DECLARE @temp NVARCHAR(20) DECLARE myCurse CURSOR FOR SELECT spid FROM sys sysprocesses WHERE dbid = DB_ID(& 39;YourDatabaseName& 39;) OPEN myCu

杀死数据库连接:

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
相关文章
最新文章
热点推荐