Sql 查询活动连接和断开所有连接
SELECT * FROM master..sysprocesses WHERE dbid=DB_ID('db')
db换成对应的数据库名即可
断开所有活动连接的存在过程方法
ALTER PROC [dbo].[P_KillConnections] @dbname VARCHAR(200) AS DECLARE @sql NVARCHAR(500) DECLARE @spid NVARCHAR(20) DECLARE #tb CURSOR FOR SELECT spid=CAST(spid AS VARCHAR(20)) FROM master..sysprocesses WHERE dbid=DB_ID(@dbname) 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