DECLARE @sql NVARCHAR(MAX),@currDbName NVARCHAR(100)
SET @currDbName='AdventureWorks2014' --如果在当前库上执行,可改为: SET @currDbName = DB_NAME()
WHILE EXISTS( SELECT 1 FROM sys.sysprocesses WHERE dbid=DB_ID(@currDbName) AND spid!=@@SPID )
BEGIN
SELECT TOP 1 @sql='kill '+CAST(spid AS NVARCHAR(50)) FROM sys.sysprocesses WHERE dbid=DB_ID(@currDbName) AND spid!=@@SPID
EXEC (@sql)
END
SQL Server: 快速清除当前库所有进程
最新推荐文章于 2023-03-06 10:17:49 发布