Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

run two queries at the same tiime Expand / Collapse
Author
Message
Posted Tuesday, October 22, 2013 5:29 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, July 9, 2014 8:24 AM
Points: 194, Visits: 1,087
I have two queries

For example

query1: select * from table1

query2: select * from table2

what I want both the queries run at the same time in the query analyzer. Please guide me how to do that
Post #1507068
Posted Tuesday, October 22, 2013 5:44 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, April 8, 2014 6:13 AM
Points: 1,694, Visits: 19,550
Decide on a suitable time for them both to start and then in one window run this

WAITFOR TIME '13:00:00'
select * from table1

and run this in the other

WAITFOR TIME '13:00:00'
select * from table2



____________________________________________________

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537

Never approach a goat from the front, a horse from the rear, or a fool from any direction.
Post #1507073
Posted Tuesday, October 22, 2013 6:47 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, July 25, 2014 3:11 PM
Points: 15,517, Visits: 27,898
Using just SSMS and SSMS only, you can't run them at the same time. You can run them from two different windows, but there will be lag while you click between the windows. If you must start them at exactly the same time, you can use Agent as was suggested, or you can look into threading the execution in PowerShell (or a programming language). Then you can get simultaneous execution.

Why are you trying to execute them at the same time?


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1507099
Posted Tuesday, October 22, 2013 1:28 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, July 25, 2014 5:41 AM
Points: 128, Visits: 820
A connection can't really multitask; the question is flawed. Sqlserver is quite like its own mini multitasking OS in that it implements its own round-robin task switching. To get the illusion of same time execution, do what a previous poster said with using two connections and WAITFOR TIME. You can also use sqlagent to schedule jobs on different connections. You can also use service broker to queue tasks to different connections. Connections get stuck in wait states waiting on disk, cpu, network, etc so technically virtually everything is single threaded.

Maybe explain deeper what you are trying to accomplish.
Post #1507322
Posted Tuesday, October 22, 2013 6:20 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:58 AM
Points: 36,756, Visits: 31,213
Smash125 (10/22/2013)
I have two queries

For example

query1: select * from table1

query2: select * from table2

what I want both the queries run at the same time in the query analyzer. Please guide me how to do that


Are you trying to get parallel processing out of a stored procedure or are you just trying to play with scripts? There is a way to get parallel processing out of a stored procedure using jobs (call sp_start_job to start two different jobs) but it basically emulates what Mark posted. The proc would start each job and the jobs will run asynchronously.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1507433
Posted Tuesday, October 22, 2013 6:32 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:58 AM
Points: 36,756, Visits: 31,213
Bill Talada (10/22/2013)
...the question is flawed.


BWAA-HAAA!!!! How can a question be flawed when the OP doesn't know?


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1507437
Posted Tuesday, October 22, 2013 7:40 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, July 25, 2014 5:41 AM
Points: 128, Visits: 820
The question is basically flawed because for now we are stuck with the Von Neumann architecture in our business computers where everything is single-threaded through the CPU in charge. Task-switching gives the illusion of parallel execution when done in short enough durations per task. The best way to multitask has always been to use two separate computers.
Post #1507442
Posted Tuesday, October 22, 2013 9:49 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 5:53 PM
Points: 33,063, Visits: 15,179
You could use osql/SQLCMD to do this as well.

Use the START command in a command prompt to spawn a process running your query and run that twice consecutively. It will get you something as close to simultaneous as starting two jobs.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1507457
Posted Tuesday, October 22, 2013 11:48 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:58 AM
Points: 36,756, Visits: 31,213
Bill Talada (10/22/2013)
The question is basically flawed because for now we are stuck with the Von Neumann architecture in our business computers where everything is single-threaded through the CPU in charge. Task-switching gives the illusion of parallel execution when done in short enough durations per task. The best way to multitask has always been to use two separate computers.


Not stuck at all when you have 16 core sitting in your machine.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1507465
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse