In Sql Server to PAUSE OR SLEEP OR WAIT the execution of the script for specified period of time say 10 hours or 10 minutes or 10 seconds or 10 millisecond etc we can use the WAITFOR DELAY command.
Let us understand WAITFOR DELAY command with extensive list of examples:
Example 1: WAIT or SLEEP for 10 MilliSeconds
To wait for 10 MilliSeconds, we can write the WAITFOR DELAY statement like below
WAITFOR DELAY '00:00:00.010'
Example 2: WAIT or SLEEP for 10 Seconds
To wait for 10 Seconds, we can write the WAITFOR DELAY statement like below
WAITFOR DELAY '00:00:10.000'
Example 3: WAIT or SLEEP for 10 Minutes
To wait for 10 Minutes, we can write the WAITFOR DELAY statement like below
WAITFOR DELAY '00:10:00.000'
Example 4: WAIT or SLEEP for 10 Hours
To wait for 10 Hours, we can write the WAITFOR DELAY statement like below
WAITFOR DELAY '10:00:00.000'
Example 5: WAIT or SLEEP for 90 Seconds or 1 Minute and 30 Seconds
To wait for 90 Seconds or 1 Minute and 30 Seconds, we can write the WAITFOR DELAY statement like below:
WAITFOR DELAY '00:01:30.000'
Example 6: Passing Variable for the WAITFOR DELAY statement
We can pass a local variable to the WAITFOR DELAY control flow statement as shown in the below example
DECLARE @WaitForTime AS VARCHAR(12) = '00:00:10.000' WAITFOR DELAY @WaitForTime