03 July 2007 00:14
leo.pasta
Instant gratification
I expected that my first “real” post would be about one of the features that had more appeal to me on SQL Server Katmai, but I will have to post about a discovery that was so useful to me, and yet so basic that I am almost ashamed to have found it only today. So let’s put aside my desire to pretend I knew it for a long time and post it, after all I hope that there is at least a couple of DBAs who still don’t know it:
Having beginning to work with VLDB recently, I am more involved in optimizing long running processes. So it is very useful to print the timings of the events as they occur. Since my Sybase days I always used the plain old “PRINT GETDATE()”.
But this will only print the output at the end of the batch, and when you are optimizing a job that takes 4 hours to complete, you get pretty anxious to know what the hell he is doing at any given time, even to decide if its better to cancel and try another change.
The solution is simple, instead of PRINTs, use:
DECLARE @Message varchar (100)
SET @Message = '<Step Description>: ' + CONVERT (CHAR (20), GETDATE (), 8)
RAISERROR (@Message, 0, 1) WITH NOWAIT
And you get the output as soon as they are generated.
By the way, the WITH NOWAIT option is properly described in the good old BOL.
Filed under: SQL Server