tsql script waitfor delay and waitfor time in SQL Server

If you want to create a wait time or delay between execution of two SQL Statements in the same script you can use WAITFOR DELAY command.

It is helpful when you want your script to wait before executing the next statement, you can also use TIME to execute the script at given time.

This first script is an example of DELAY for a specific amount of time

USE NORTHWIND
WAITFOR DELAY '00:01:00'
BEGIN
SELECT * FROM CUSTOMERS
END

Delays the execution of the T-SQL statement by 1 minute. To delay by an hour, you would use '01:00:00'. You can specify a maximum of 24 hours.

To execute the T-SQL statement at the given time.

USE NORTHWIND
WAITFOR TIME '11:23:00'
BEGIN
SELECT * FROM CUSTOMERS
END

Waits for the execution of the T-Sql statement till the time '11:23 A.M'. (Time is in 24 hour format)

 


SQL Server DBA

I am a SQL Server DBA with almost 9 years of experience in database technologies.

Right now I am in process of redesigning this website in ASP.NET 2.0 and AJAX. The main purpose of new SQL DBA website is to offer more help to database professionals and make it easy for me to update contents on regular basis.