--delay or suspend execution of the program using the WAITFOR statement
--waitfor{delay ' time ' |time ' time '}
Delay is the maximum interval of time to 24 hours
Time is specified when execution
WAITFOR DELAY ' 00:00:10 '--delayed 10 seconds
A. Using WAITFOR time
The following example executes a stored procedure sp_update_jobat night 10:20 (22:20).
Copy Code
Use msdb; EXECUTE sp_add_job @job_name = ' testjob '; Beginwaitfor time ' 22:20 '; EXECUTE sp_update_job @job_name = ' testjob ', @new_name = ' updatedjob '; END; GO
B. Using WAITFOR DELAY
The following example executes a stored procedure after a two-hour delay.
Copy Code
Beginwaitfor DELAY ' 02:00 '; EXECUTE sp_helpdb; END; GO
This delay is usually not retired nature ah. However, the problem occurs when the subscription is synchronized, or when the amount of data is too large. Lose the data, or the table lock dead. The problem is very much, the extra 1 should be considered in batches. The extra 5000 must be in batches.
SQL Delay operation