我使用 RAISERROR 从存储过程而不是使用 PRINT 生成进度输出,以避免 PRINT 对输出进行缓冲。现在我发现 RAISERROR 将在 500 次打印后开始缓冲。有没有办法解决这种行为?下面的查询将表明我的观点:
DECLARE @i INT = 0
WHILE @i < 50000
BEGIN
SET @i = @i + 1
RAISERROR('%i prints', 0,1 , @i) with nowait;
IF @i > 500 --<--after 500 prints RAISERROR starts buffering 50 prints before flushing.
WAITFOR DELAY '00:00:00.050';
END;