Tag Archives: SQL SLEEP Command

SLEEP Command in Sql Server

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.

SYNTAX
waitfor-delay-in-syntax

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'

RESULT:
wait-for-10-milliseconds-in-sql-server

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'

RESULT:
wait-for-10-seconds-in-sql-server

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'

RESULT:
wait-for-10-minutes-in-sql-server

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'

RESULT:
wait-for-1-minute-and-30-seconds-in-sql-server

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

RESULT:
passing-local-variable-as-a-parameter-for-the-waitfor-delay-statement