SQL Server deferred execution

Source: Internet
Author: User

In the following example (22: 20) Execute the Stored ProcedureSp_update_job. Use MSDB;
Execute Sp_add_job @ Job_name = ' Testjob ' ;
Begin Waitfor Time ' 22: ' ;
Execute Sp_update_job @ Job_name = ' Testjob ' , @ New_name = ' Updatedjob ' ;
End ;
Go

In the following example, the stored procedure is executed after two hours of delay. Note: delay cannot exceed 24 hours at most

Begin
WaitforDelay'';
ExecuteSp_helpdb;
End;
Go

 

Use Adventureworks2008r2; Go If Object_id ( ' DBO. timedelay_hh_mm_ss ' , ' P ' ) Is Not Null Drop Procedure DBO. timedelay_hh_mm_ss; Go Create Procedure DBO. timedelay_hh_mm_ss ( @ Delaylength Char ( 8 ) = ' 00:00:00 ' ) As Declare @ Returninfo Varchar ( 255 ) If Isdate ( ' 2000-01-01 ' + @ Delaylength + ' . 000 ' ) = 0 Begin Select @ Returninfo = ' Invalid time ' + @ Delaylength + ' , HH: mm: SS, submitted. ' ; -- This print statement is for testing, not use in production. Print @ Returninfo Return ( 1 ) End Begin Waitfor Delay @ Delaylength Select @ Returninfo = ' A total time ' + @ Delaylength + ' , HH: mm: SS, has elapsed! Your time is up. ' -- This print statement is for testing, not use in production. Print @ Returninfo ; End ; Go /* This statement executes the DBO. timedelay_hh_mm_ss procedure. */ Exec Timedelay_hh_mm_ss ' 00:00:10 ' ; Go

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.