Search code examples
sqlsql-serverjob-schedulingsql-agent-jobsql-job

In SQL Server Jobs Two stored procedures Execute one by one or simultaneously?


I want to create a JOB in SQL Server 2012, to execute two related stored procedures.

Exec my_First_Procedure
Exec my_Second_Procedure

If I create the JOB like above, the second one start the execution after the first one completed, or both the Queries Executed simultaneously?

Help me to find it. Thanks in advice.


Solution

  • T-SQL is a scripting language. The statements are executed sequentially. In fact, this is true of almost all computer languages. Usually, you have to go through some effort to execute things in parallel.

    If the first statement fails, then the second statement is not executed.

    SQL Server does have mechanisms for running things in parallel. One method is rather complicated, using the message queue functionality. You can read about message queuing here. Or there are various blogs on the subject of asynchronous execution, such as this one.

    Another option is to use jobs. Simply schedule two jobs to run at the same time.