Sql Server : How to introduce wait between running T-Sql statements (WAITFOR DELAY)
- Posted by Sqltimes
- On January 16, 2016
- 0 Comments
Quick one today:
Occassionally, we need to introduce forced wait or delays when running some T-Sql statements. There is an easy way to accomplish it.
There are a couple of ways to implement this.
- Relative wait : Introduce wait for a few seconds/minutes/hours before running the next command
- Absolute wait : Wait until a particular time, then run the next command. Ex: Run next command at 10:30 pM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
-- -- Relative Wait: Wait for 10 minutes before running backup -- USE master GO WAITFOR DELAY '00:10:00' -- wait for 10 minutes before running backup BACKUP DATABASE master TO DISK = N 'S:\master.bak' GO -- -- Absolute Wait : Do something at 10:30 PM -- USE master GO WAITFOR TIME '00:22:30' -- run back up at 10:30 PM BACKUP DATABASE master TO DISK = N 'S:\master.bak' GO |
Hope this helps,
_Sqltimes
0 Comments