开发者

Thread inside a Loop? SQL Server

开发者 https://www.devze.com 2023-02-15 02:09 出处:网络
Can something like#pragma_omp (OpenMP) in C for loops #pragma omp parallel for for (ii = 0; ii < nrows; ii++){

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]开发者_C百科[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??


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号