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

Rajesh Kumar Yadav 20 Reputation points
2023-11-21T15:30:27.79+00:00

hi,

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
Transact-SQL
Transact-SQL
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
    2023-11-21T16:46:47.31+00:00

    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
    2023-11-21T23:31:04.4033333+00:00

    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
    2023-11-22T12:44:53.6+00:00

    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.