SQL SERVER – Running SQL Agent Job After Completing Another Job

A really very interesting situation I faced with my client while working on Comprehensive Database Performance Health Check. They wanted to run SQL Server Agent Job After Completing Another Job. Well, it is possible and very easy to do.

SQL SERVER - Running SQL Agent Job After Completing Another Job Agent-Job-800x262

There is no need to guess the time of the first job to complete or also there is no need to write complicated jobs to look for job status or job completion history. It is very easy to start another job when one job completes.

When you are creating various steps for the Job, create the last step with the help of the system stored procedure sp_start_job.

Start Agent Job

USE msdb ;  
GO
EXEC dbo.sp_start_job N'Name of Job' ;  
GO 

When the last step runs with the above SP, it will automatically run the next job. The solution is very simple but I have not seen many using this in the industry.

Here are my few recent videos and I would like to know what is your feedback about them. Do not forget to subscribe SQL in Sixty Seconds series.

Reference: Pinal Dave (http://blog.SQLAuthority.com)

SQL Agent Job, SQL Scripts, SQL Server
Previous Post
SQL SERVER – Deny Drop Permission for a Table
Next Post
SQL SERVER – Easiest Way to Copy All Stored Procedure Definitions

Related Posts

2 Comments. Leave new

  • Mike Michalicek
    September 8, 2021 6:10 am

    I have used this method many times. I am surprised to hear you state “I have not seen many using this in the industry.”.

    Reply
  • What if the first job is executed on a different server and the execution of 2nd job causes deadlocks if the first job is still running? Because the source for the 2nd job is the destination for first … How will you implement a solution for that?

    Reply

Leave a Reply