首页 > 代码库 > SQL Server 2008杀死数据库连接

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


SQL Server 2008杀死数据库连接