DECLARE @sql NVARCHAR(MAX),@currDbName NVARCHAR(100)
SET @currDbName=DB_NAME() --如果在当前库上执行,可改为: SET @currDbName = DB_NAME()
WHILE EXISTS( SELECT 1 FROM sys.sysprocesses WHERE dbid=DB_ID(@currDbName) AND [email protected]@SPID )
BEGIN
SELECT TOP 1 @sql=‘kill ‘+CAST(spid AS NVARCHAR(50)) FROM sys.sysprocesses WHERE dbid=DB_ID(@currDbName) AND [email protected]@SPID
EXEC (@sql)
END
时间: 2024-11-01 12:34:12