Caveman's Blog

My commitment to learning.

SQL Server: Delay function “WaitFor”

with 3 comments

Sql Server provides a function called “WaitFor”” that can be called to block the execution of your T-SQL code for a specified time or time interval is reached, or a specified statement modifies or returns at least one row.  The WaitFor function can be called with two sytles:

1) to wait for a certain point in time

--Code execution is blocked till 6:30 pm

2) to wait for a certain amount of time:

--Code execution is blocked for 4 seconds
WAITFOR DELAY '00:00:04'

WaitFor has to be employed with a cautious manner for the following reasons:

1. No other requests can run on the same transaction that the WaitFor is running
2. Cursors cannot be opened on WaitFor statement.
3. Views cannot be defined on WaitFor statemtent


1. MSDN Online


Written by cavemansblog

February 27, 2012 at 7:55 pm

3 Responses

Subscribe to comments with RSS.

  1. I really didn’t realize this function existed. What would you recommend for usage?


    February 27, 2012 at 8:41 pm

    • I am new to this function as well. If I were to use this function I would test the hell out of my code 😉 One place I could think of using this function is, when the subsequent action in my SQL code is dependent on a the execution of a preceding logic to be executed in a given time frame.


      February 28, 2012 at 12:47 am

      • Yeah, I would have to test the hell out of it!


        February 28, 2012 at 8:23 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: