103

In SQL Server 2005 Management Studio, it appears that the output of PRINT statements doesn't appear immediately: If I have a PRINT statement followed by a long-running statement, the PRINT output doesn't appear until after the following statement.

Is there any way to flush the output earlier? I'm running some upgrade scripts that take an age to complete, and I'd like to know how far along the script is (so I know whether to wait a few minutes and then start the next one, or whether to go to lunch).

ConcernedOfTunbridgeWells
  • 64,444
  • 15
  • 143
  • 197
Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • 1
    Do you have a "GO" between the PRINT and long running statement? – Bernhard Hofmann Dec 08 '08 at 12:26
  • 7
    possible duplicate of [How do I flush the PRINT buffer in TSQL?](http://stackoverflow.com/questions/306945/how-do-i-flush-the-print-buffer-in-tsql) – usr Apr 29 '14 at 15:53
  • 1
    Roger: I saw your ranting at http://blog.differentpla.net/blog/2006/10/19/bad-ui-why-sql-query-analyzer-sucks. I have the same complaint. Why do I need to see my login info and the words "SQLQuery999.sql " on that short space which crowds out all the other important info, right?! Glad to see you speak up although it won't change a thing. I have to resort to use the interface provided by the Visual Studio using the Server explorer so less deadly accident can happen. – Jenna Leaf Jan 11 '18 at 17:04

1 Answers1

160

No. Output of PRINT statements will only be returned when a transaction is committed, when other record sets are returned or a statement is completed (go statement terminator in a SQL batch). You can use raiserror at non-fatal error levels (0-18) to get immediate feedback of this sort. For example:

RAISERROR ('Foo', 10, 1) WITH NOWAIT
ConcernedOfTunbridgeWells
  • 64,444
  • 15
  • 143
  • 197