如何在 TSQL 中刷新 PRINT 缓冲区? [英] How do I flush the PRINT buffer in TSQL?

查看:53
本文介绍了如何在 TSQL 中刷新 PRINT 缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试调试 SQL Server 2005 中有一个运行时间很长的存储过程,我正在使用打印"命令来完成它.问题是,我只是在 sproc 的最后从 SQL Server 取回消息 - 我希望能够在 sproc 运行时刷新消息缓冲区并立即查看这些消息,而不是在非常结束.

I have a very long-running stored procedure in SQL Server 2005 that I'm trying to debug, and I'm using the 'print' command to do it. The problem is, I'm only getting the messages back from SQL Server at the very end of my sproc - I'd like to be able to flush the message buffer and see these messages immediately during the sproc's runtime, rather than at the very end.

推荐答案

使用 RAISERROR 函数:

Use the RAISERROR function:

RAISERROR( 'This message will show up right away...',0,1) WITH NOWAIT

您不应该用 raiserror 完全替换所有打印件.如果您在某处有一个循环或大游标,只需每次迭代执行一次或两次,甚至每隔几次迭代就执行一次.

You shouldn't completely replace all your prints with raiserror. If you have a loop or large cursor somewhere just do it once or twice per iteration or even just every several iterations.

另外:我第一次在这个链接上了解了 RAISERROR,我现在认为它是 SQL Server 错误处理的权威来源,绝对值得一读:
http://www.sommarskog.se/error-handling-I.html

Also: I first learned about RAISERROR at this link, which I now consider the definitive source on SQL Server Error handling and definitely worth a read:
http://www.sommarskog.se/error-handling-I.html

这篇关于如何在 TSQL 中刷新 PRINT 缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆