Return unlocked rows in a “select top n” query

后端 未结 4 2022
再見小時候
再見小時候 2021-01-02 18:17

I need to have a MsSql database table and another 8 (identical) processes accessing the same table in parallel - making a select top n, processing those n rows, and updating

4条回答
  •  生来不讨喜
    2021-01-02 18:53

    The best idea if you want to select records in this manner would be to use a counter in a separate table.

    You really don't want to be locking rows on a production database exclusively for any great period of time, therefore I would recommend using a counter. This way only one of your processes would be able to grab that counter number at a time (as it will lock as it is being updated) which will give you the concurrency that you need.

    If you need a hand writing the tables and procedures that will do this (simply and safely as you put it!) just ask.

提交回复
热议问题