Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL how to make a job run a job?

Tags:

sql

jobs

I'd like to call another job immediately after first one has finished, or to be more precise is it possible to call an entire sql job via a job step. I'd like to avoid merging these jobs into 1 so I wonder if this solution is possible?

like image 463
ilija veselica Avatar asked May 23 '12 13:05

ilija veselica


People also ask

How do you trigger a job in SQL?

SQL Server Agent is the job scheduling tool for SQL Server. To execute a job on demand using the GUI, open the SQL Server Agent tree, expand Jobs, select the job you want to run, right click on that job and click 'Start Job' and the job will execute.

How do you're run the job in SQL Server?

Under the job step properties click on "advanced", you can then restart the job on step 1. It also gives you the option to retry a number of times before aborting and ending.

Can you run a SQL job as a different user?

When you create a SQL Server Agent Job of any type other than T-SQL you'll have an extra drop-down box that will allow you to select the credential that you want to use. Select the credential from the drop-down, and the next time the job runs, the job step will be run as the account specified in the credential.


2 Answers

Yes, you can execute a job by using this stored procedure. In your case, you can simply add a step to the end of your first job, to call the name of the job you want executed next.

EXEC msdb.dbo.sp_start_job N'Job Name';

See sp_start_job (Transact-SQL) for more information.

like image 188
mservidio Avatar answered Oct 08 '22 07:10

mservidio


create a T-SQl Step and use EXEC msdb.dbo.sp_start_job N'YourJob';

like image 42
Diego Avatar answered Oct 08 '22 07:10

Diego