-1

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.

Asad Mehmood
  • 292
  • 2
  • 10
  • 20

2 Answers2

0

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

Rajeev Bera
  • 2,021
  • 1
  • 16
  • 30
0

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.

  • Thank You @Tom Hammerbacher for your response. One more question. Is it possible to execute Create+Insert Query, Select Query and assume an update query in parallel? – Asad Mehmood Mar 30 '22 at 07:09
  • You are welcome! As far as i know this is not possible by default without changing the server to include multiple threads. This may help you but it requires changes on server side: https://www.percona.com/blog/2019/01/23/mysql-8-0-14-a-road-to-parallel-query-execution-is-wide-open/ – Tom Hammerbacher Mar 30 '22 at 09:20