本文介绍了为什么人们在 T-SQL 中使用 RaiseError 而不是 Print的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了以下两个查询,它们同时执行.但是我仍然看到许多存储过程中使用 RaiseError 而不是打印.
I have tried both the below queries and they perform in same time. But still I have seen RaiseError used in many stored procedures instead of print.
查询 1:
BEGIN
WAITFOR DELAY '00:00:03.00'
PRINT 'DELAY 1 HAS ENDED'
WAITFOR DELAY '00:00:03.00'
PRINT 'DELAY 2 HAS ENDED'
END
查询 2:
BEGIN
WAITFOR DELAY '00:00:03.00'
RAISERROR ('DELAY 1 HAS ENDED', 10,1) WITH NOWAIT
WAITFOR DELAY '00:00:03.00'
RAISERROR ('DELAY 2 HAS ENDED', 10,1) WITH NOWAIT
END
两者都只在 6 秒后给出所需的输出(我已经在 SQL Server 2008 R2 中检查过)
Both give the desired output only after 6 seconds (I have checked this in SQL Server 2008 R2)
推荐答案
我的服务器版本与您相同,查询 2 在 3 秒后打印第一个结果(如预期).您必须在 Microsoft SQL Server Management Studio 中自行切换到消息"选项卡才能查看消息.
I have the same server version as you did, and Query 2 prints the first result after 3 seconds (as expected). You have to switch to the Message tab on your own in Microsoft SQL Server Management Studio to see the message.
这篇关于为什么人们在 T-SQL 中使用 RaiseError 而不是 Print的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!