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