Use wait delay in SQL Server for waiting or sleep

Use wait delay in SQL Server for waiting or sleep.

WAITFOR DELAY ‘000:00:01’ is used to put the system to sleep before executing the next query.
For 1 minute delay: WAITFOR DELAY ‘000:01:00’

Example: Put 5-second detail in the script to execute your SQL Query:

DECLARE @i INT = 1;
WHILE (@i <= 60)
 BEGIN
  WAITFOR DELAY '00:00:05'
       /*Your Script*/
	   SET  @i = @i + 1;
END 

Example: Use the Wait Delay option in Procedure to wait for 30 seconds before executing the SQL Server Select statement:

ALTER PROCEDURE testwaitfor30
AS
    SET NOCOUNT ON;
    waitfor delay '00:00:30'
	SELECT LastName, FirstName, JobTitle, Department
    FROM HumanResources.vEmployeeDepartment;

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.