SDU Tools: Sleep

Most of the time, we want SQL Server T-SQL queries to run as fast as possible, just the same as we want programs in any programming language to run as fast as possible.

But there are times when you want SQL Server to just sleep for a while, and without tying up system resources (like spinning around on the CPU).

Example of this would be waiting for new entries in Service Broker queues, or waiting to retry deadlocks.

In most programming languages, there is a method just called Sleep that takes the number of seconds (sometimes milliseconds) that you want to wait.

SQL Server has a WAITFOR command but it takes a duration as a parameter (which is a bit messy to work with) and most people wouldn't think to look for that command anyway.

So we added a tool to the SDU Tools collection that's just called Sleep. It takes a number of seconds as a parameter. It still calls WAITFOR under the covers but is just easier to work with, and easier to find.

EXEC SDU_Tools.Sleep 5;

You can see it in action here:

You can find out more about our free SDU Tools here:

http://sdutools.sqldownunder.com

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *