title: RAISERROR WITH NOWAIT not so immediate?
body: <p>I previously asked a question on how to do a <code>PRINT</code> that gives output immediately while the rest of the script is still running (See: <a href="https://stackoverflow.com/questions/10132847/how-to-see-progress-of-running-sql-stored-procedures">How to see progress of running SQL stored procedures?</a>). The simple answer is to use:</p>
  
  <pre><code>RAISERROR ('My message', 0, 1) WITH NOWAIT
  </code></pre>
  
  <p>However, I noticed that the returned output is not always immediate, especially when it returns a lot of results. As a simple experiment, consider the following script:</p>
  
  <pre><code>DECLARE @count INT
  SET @count = 1
  
  WHILE @count &lt;= 5000
  BEGIN
      RAISERROR ('Message %d', 0, 1, @count) WITH NOWAIT
      WAITFOR DELAY '00:00:00.01'
      SET @count = @count + 1
  END
  </code></pre>
  
  <p>The above script will spits out 5000 lines of text. If you run the script, you will notice:</p>
  
  <ul>
  <li>For the first 500 lines (1 - 500 lines), it returns each output line immediately.</li>
  <li>For the next 500 lines (501 - 1000 lines), it returns the output once every 50 lines. (All 50 lines will be batched together and returned only at the end of each 50th line.)</li>
  <li>For every line after that (1001 - * lines), it returns the output once every 100 lines. (All 100 lines will be batched together and returned only at the end of each 100th line.)</li>
  </ul>
  
  <p>So that means after the first 500 lines, the <code>RAISERROR WITH NOWAIT</code> no longer work as expected, and cause problems to me because I want to see the progress of my very long running script.</p>
  
  <p>So my question: Is there any way to disable this 'batched' behaviour and make it always return immediately?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> I'm using SSMS (SQL Server Management Studio) to run the above script . It seems to affect all versions (both SSMS and SQL Server), and whether the output is set to "Results to Text" or "Results to Grid" makes no difference.</p>
  
  <p><strong>EDIT:</strong> Apparently, this batched behaviour happens after 500 lines, <em>regardless</em> of the number of bytes. So, I've updated the question above accordingly.</p>
  
  <p><strong>EDIT:</strong> Thanks to <strong>Fredou</strong> for pointing out that this is an issue with SSMS and third party tools like <em>LinqPad</em> will not have this issue.</p>
  
  <p>However, I found out that <em>LinqPad</em> doesn't output immediately either when you have table results in the output. For example, consider the following code:</p>
  
  <pre><code>RAISERROR ('You should see this immediately', 0, 1) WITH NOWAIT
  SELECT * FROM master.sys.databases
  RAISERROR ('You should see this immediately too, along with a table above.', 0, 1) WITH NOWAIT
  WAITFOR DELAY '00:00:05'
  RAISERROR ('You should see this 5 seconds later...', 0, 1) WITH NOWAIT
  </code></pre>
  
  <p>When you run the above script in LinqPad, only the first line is output immediately. The rest will only output after 5 seconds...</p>
  
  <p>So, anyone know of a good light-weight alternative to SSMS that is free, does not require installation and will work with immediate outputs of RAISERROR WITH NOWAIT mixed with table results?</p>