Specifies a specific time, a time interval, or an event for the execution of a statement block, stored procedure, or transaction.
waitfor { delay time | time time | errorexit | processexit | mirrorexit }
instructs Adaptive Server to wait until the specified amount of time has passed, up to a maximum of 24 hours.
instructs Adaptive Server to wait until the specified time.
a time in one of the acceptable formats for datetime data, or a variable of character type. You cannot specify dates—the date portion of the datetime value is not allowed.
instructs Adaptive Server to wait until a kernel or user process terminates abnormally.
instructs Adaptive Server to wait until a kernel or user process terminates for any reason.
instructs Adaptive Server to wait for a mirror failure.
At 2:20 p.m., the chess table is updated with my next move, and a procedure called sendmail inserts a row in a table owned by Judy, notifying her that a new move now exists in the chess table:
begin waitfor time "14:20" insert chess(next_move) values('Q-KR5') execute sendmail 'judy' end
After 10 seconds, Adaptive Server prints the message specified:
declare @var char(8) select @var = "00:00:10" begin waitfor delay @var print "Ten seconds have passed. Your time is up." end
After any process exits abnormally, Adaptive Server prints the message specified:
begin waitfor errorexit print "Process exited abnormally!" end
After issuing the waitfor command, you cannot use your connection to Adaptive Server until the time or event that you specified occurs.
You can use waitfor errorexit with a procedure that kills the abnormally terminated process, to free system resources that would otherwise be taken up by an infected process.
To find out which process terminated, check the sysprocesses table with sp_who.
The time you specify with waitfor time or waitfor delay can include hours, minutes, and seconds. Use the format “hh:mi:ss”, as described in “Date and time datatypes.”
The following example instructs Adaptive Server to wait until 4:23 p.m:
waitfor time "16:23"
This statement instructs Adaptive Server to wait for 1 hour and 30 minutes:
waitfor delay "01:30"
Changes in system time (such as setting the clock back for Daylight Savings Time) can delay the waitfor command.
You can use waitfor mirrorexit within a DB-Library program to notify users when there is a mirror failure.
SQL92 – Compliance level: Transact-SQL extension.
waitfor permission defaults to all users. No permission is required to use it.
Commands – begin...end
Datatypes – Date and time datatypes
System procedures – sp_who