Home > Software engineering >  How to execute multiple SQL queries at same time
How to execute multiple SQL queries at same time

Time:03-30

I want to know If we can execute multiple queries at the same time in MYSQL/SQL. Let me explain a case scenario to elaborate my statement further.

Let's Assume, We have to create and load two tables.create table tbl1(col,col,col,col...); Insert Into tbl1 (val,val,val,val...) and other query as create table tbl2(col,col,col,col...); Insert Into tbl2 (val,val,val,val...). Now, When I execute the statement the flow will be

  1. Create Table1
  2. Insert Into Table1
  3. Create Table2
  4. Insert Into Table2

Is there any method We can use to minimize these 4 steps into a single step? Similar to the functionality of threads that run in parrallel.

CodePudding user response:

You can use two different instances of SSMS or may be different tabs within SSMS.

Other solution to run 2 queries at the same time with a maintenance plan. Here is the link for more details

CodePudding user response:

You can chain multiple queries by using the ";", see here for further details: How to run multiple SQL queries?.

In your setup, 1. needs to be executed before 2. (same is true for 3. before 4.) because you cannot insert data into a database that did not exist. So running these 4 queries in parallel is not possible. However, running 1 2 and 3 4 in parallel is possible.

  • Related