home / software / tips and tricks / How to Add Delay Function – WAITFOR clause in SQL Server scripts?

How to Add Delay Function – WAITFOR clause in SQL Server scripts?

Updated:  10/14/2011 09:10 AM
Author:  Shiju Mathews

Status:    Resolved.


Blocks the execution of a batch, stored procedure, or transaction until a specified time or time interval is reached, or a specified statement modifies or returns at least one row.

While executing the WAITFOR statement, the transaction is running and no other requests can run under the same transaction. If the server is busy, the thread may not be immediately scheduled; therefore, the time delay may be longer than the specified time. WAITFOR can be used with query but not with UDF or cursors. WAITFOR wait till TIMEOUT is reached.

Sample Code:

WAITFOR DELAY 'Delay_Time'

Where Delay_Time is the time dealy before the execution of the next statement.

Example:
Tags: How to Add Delay Function – WAITFOR clause in SQL Server scripts?
Updated on: April 2024