Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
CrazyT
Yak Posting Veteran
73 Posts |
Posted - 2011-11-18 : 13:17:33
|
| i am writing a multithreaded app that grabs records by 100 and processes them.how do i write a select query that thread 1 grabs the first 100 rows and update a status field to 1 and thread 2 grabs the next 100 row and updates the status feild to 1my problem is thread one grabs its 100 and starts updating and thread 2 selects some of the same records becuase they havent had their status feild updated yet. so Im not getting a 100 records per thread |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-11-18 : 13:22:39
|
| Use a transaction. |
 |
|
|
CrazyT
Yak Posting Veteran
73 Posts |
Posted - 2011-11-18 : 14:41:16
|
| thanks |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-11-18 : 15:23:24
|
| It depends on how you are "grabbing" them and "updating" them. A transaction probably isn't the answer. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-19 : 01:51:34
|
| another way is to have a updateowner field and each thread will update it to a unique id when it starts. Any threads that starts subsquently will only fetches those rows where updateowner field is null which will avoid it from picking rows already picked by thread1 again.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|