sql command written in cmd that is .bat file is synchronous or asynchronous

Rajesh Kumar Yadav 20 Reputation points


I call few stored procedure from a .bat file  and .bat file is executed from micorsoft windows sheduler, need to know that , does it call in syncronious or asyncronious way?

i.e firstly it executes the stored procedure in first line  and waits for the completion of the sp then it goes to second line for the second stored procedure?

yours sincerly

Azure SQL Database
Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,143 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,298 questions
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,597 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Alberto Morillo 33,421 Reputation points MVP

    Batch file (.bat file) execution on Windows or DOS executes commands in synchronous mode by default, meaning that it waits for a command to finish before continuing with the rest. However, you can use the START command to execute commands in asynchronous mode, meaning that they run in parallel and do not wait for each other.

    "In a batch script, a START command without /wait will run the program and just continue, so a script containing nothing but a START command will close the CMD console and leave the new program running."

    Source here.

    0 comments No comments

  2. Bruce (SqlWork.com) 61,101 Reputation points

    as a .bat file needs a program to run sql commands, you would need to tell us the program or show the code if its custom.

  3. Dan Guzman 9,226 Reputation points

    Q1)that is first call should execute first in a sessionid @spid then after the complition this spid should  go away from my activity monitor then next call of the same stored procedure should execute in diffrent @spid. ( that is at one time i must see only one spid in my activity monitor executing a query of the above stored procedure)

    Correct. Each sqlmd will open a new connection, execute the proc, and close the connection. You will never have more than session at a time execute the proc from this bat file. Be aware that the second sqlcmd might be assigned the same session_id as the first sqlcmd by chance but it is a new connection and unrelated to the first execution.