Using the WAITFOR keyword in SQL server 2000 to perform a task at a given time or after a given time

Hi

SQL server 2000 also has a WAITFOR keyword to suspend the execution of a connection for a given time interval or a specified day of time has reached. The WAITFOR command can be specified with either of the two clauses.

The delay keyword with the amount of time to be passed before the WAITFOR statement is completed. This time can be up to 24 hours. Or we can use the time keyword followed by a time to specify the completion of the WAITFOR statement.

Here are two example of using the statement.

WAITFOR DELAY '00:00:02'

SELECT * FROM CATEGORIES

This example delays the execution of the select statement by 2 seconds.

BEGIN

   WAITFOR TIME '23:00'

   DBCC CHECKALLOC

END

The above example waits until 11 PM to perform a check on the given database and make sure that all the pages in the database are allocated and used.

Remember that the connection from the application remains suspended until the WAITFOR completes. WAITFOR is best used when an application or stored procedure must suspend processing for some relatively limited amount of time.

Hope this helps
Thanks
Vikram


Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2008 Vikram Lakhotia