5

Is there native support for executing queries in parallel from a stored procedure in SQL Server 2008 R2? Take this pseudo code for example

create proc dbo.MySproc
as
   delete from SomeTable where Predicate = true [as parallel]
   delete from AnotherTable where Predicate = false [as parallel]

   [wait for queries]

   select * from SomeTable join AnotherTable on Predicate = true

I've seen examples of doing this but they require installing non native CLR procedures which is what I want to avoid.

NOTE: I'm not talking about execution plans, I mean running two non related queries at the same time async, not one after the other.

Dustin Davis
  • 14,049
  • 12
  • 60
  • 114
  • You could fire them from batch file. I do this in some processes now. Proc1 Proc2 Proc3 all execute in parallel and update a flagging table, Proc4 fires when all 3 flags are set – JNK Nov 18 '11 at 20:49
  • You mean batch file as in running them through osql? – Dustin Davis Nov 18 '11 at 20:51
  • Yes. If you use `start` the batch file will kick off the command without waiting for completion, and will launch as many `osql` sessions as you need – JNK Nov 18 '11 at 20:52

2 Answers2

6

No, there is no T-SQL syntax for controlling parallelism.

There are a number of games you can play to get something similar but they all require a non T-SQL entity. For example, SQL Server Jobs, CLR SPs that spawn multiple threads, C# app that spawns the threads, use of sqlcmd to execute T-SQL etc.

Russell McClure
  • 4,691
  • 1
  • 19
  • 20
2

How can I run sql server stored procedures in parallel? - it's about stored procedures, but maybe you'll find something useful.

Community
  • 1
  • 1
Michał Powaga
  • 20,726
  • 7
  • 45
  • 60