当前位置: 动力学知识库 > 问答 > 编程问答 >

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.

网友答案:

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.

网友答案:

You create one Store procedure for call two procedure and call from job. Both SP is execution within new job1 SP even fail one or success.

create procedure job1
as 
begin try
    begin try
        exec my_First_Procedure;
    end try 
    begin catch 
        select ERROR_MESSAGE() as messages;
    end catch

    begin try
        exec my_Second_Procedure;
    end try 
    begin catch 
        select ERROR_MESSAGE() as messages;
    end catch

    select 'Success' as messages;
end try
begin catch 
    select ERROR_MESSAGE() as messages;
end catch
分享给朋友:
您可能感兴趣的文章:
随机阅读: