October 22, 2013 at 5:29 am
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
October 22, 2013 at 5:44 am
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
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537October 22, 2013 at 6:47 am
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
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 22, 2013 at 1:28 pm
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.
October 22, 2013 at 6:20 pm
Smash125 (10/22/2013)
I have two queriesFor 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
Change is inevitable... Change for the better is not.
October 22, 2013 at 6:32 pm
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
Change is inevitable... Change for the better is not.
October 22, 2013 at 7:40 pm
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.
October 22, 2013 at 9:49 pm
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.
October 22, 2013 at 11:48 pm
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
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply