edgarmtze
edgarmtze

Reputation: 25058

Thread inside a Loop? SQL Server

Can something like #pragma_omp (OpenMP) in C for loops

#pragma omp parallel for    
for (ii = 0; ii < nrows; ii++){      
  for(jj = 0; jj < ncols; jj++){       
    for (kk = 0; kk < nrows; kk++){
       array[ii][jj] = array[ii]kk] * array[kk][jj];
    }
  }
}

be applied to a loop in SQL Server?

WHILE (...) BEGIN
END

Something to paralelize the loop, using threads, How??

Upvotes: 0

Views: 342

Answers (2)

RichardTheKiwi
RichardTheKiwi

Reputation: 107766

In a store procedure I am inserting lots of registries, so I would like to paralelize this, something to control max workers..

What you should do instead is to reformat the work as a SET based task, such as using UPDATE/INSERT into a temp table with the calculations/manipulations encapsulated on a pre-row basis. SQL Server can then parallelize the query as it sees fit.

To control the max workers, have a look at OPTION MAXDOP

Upvotes: 1

SQLMenace
SQLMenace

Reputation: 135111

In SQL Server you should use a SET based solution not loops, SQL is a SET based based language. You could use Parallel LINQ (PLINQ) to parallel some of the stuff if running from outside SQL Server

Upvotes: 3

Related Questions