Why do people use RaiseError instead of Print in T-SQL
sql, sql-server-2008-r2, t-sql
Solution
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.
Problem
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. Query 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 ``` Query 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 ``` Both give the desired output only after 6 seconds (I have checked this in SQL Server 2008 R2)