Sql-server – How to run Sql Server stored procedure in Async mode

service-brokersql serversql-server-2019sql-server-agent

Is there a way to run SQL Server 2019 stored procedures with parameters asynchronously? Calls to this SP will be made several times a day, i.e. this is not one time requirement.

Service Broker can be one option, but this is 15+ years old technology and Microsoft did not try to enhance its functionality.

Agent job can be an option, but I want to submit a job on demand "as and when required". Plus, the stored proc has parameters as well.

I came from Oracle background and there are multiple ways to submit a background job to the Database engine and it will run the job in Async manner.

Best Answer

The simplest way is to call sp_start_job and kick off an unscheduled SQL Agent Job. Parameter values can be stored in a table that the job reads from before calling the procedure.