Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1045365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:58:27+00:00 2026-05-16T15:58:27+00:00

I need to have a MsSql database table and another 8 (identical) processes accessing

  • 0

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 a column of those rows. The problem is that I need to select and process each row just once. This means that if one process got to the database and selected the top n rows, when the second process comes it should find those rows locked and select the rows from n to 2*n rows, and so on…

Is it possible to put a lock on some rows when you select them, and when someone requests top n rows which are locked to return the next rows, and not to wait for the locked ones? Seems like a long shot, but…

Another thing I was thinking – maybe not so elegant but sounds simple and safe, is to have in the database a counter for the instances which made selects on that table. The first instance that comes will increment the counter and select top n, the next one will increment the counter and select rows from n*(i-1) to n*i, and so on…

Does this sound like a good ideea? Do you have any better suggestions? Any thought is highly appreciated!

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:58:27+00:00Added an answer on May 16, 2026 at 3:58 pm

    Here’s a sample I blogged about a while ago:

    The READPAST hint is what ensures multiple processes don’t block each other when polling for records to process. Plus, in this example I have a bit field to physically “lock” a record – could be a datetime if needed.

    DECLARE @NextId INTEGER
    BEGIN TRANSACTION
    
    -- Find next available item available
    SELECT TOP 1 @NextId = ID
    FROM QueueTable WITH (UPDLOCK, READPAST)
    WHERE IsBeingProcessed = 0
    ORDER BY ID ASC
    
    -- If found, flag it to prevent being picked up again
    IF (@NextId IS NOT NULL)
        BEGIN
            UPDATE QueueTable
            SET IsBeingProcessed = 1
            WHERE ID = @NextId
        END
    
    COMMIT TRANSACTION
    
    -- Now return the queue item, if we have one
    IF (@NextId IS NOT NULL)
        SELECT * FROM QueueTable WHERE ID = @NextId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database, and a particular table in that database will need
I have table which contains double values stored in mysql database ...I need to
MYSQL Database: I have a table of data that I need to put into
I have a table inside of my mysql database which I constantly need to
I have a VARCHAR field (in table of a MySQL database) where I need
Here my code, I need to insert into mysql database I have mysql,php,android 1)
I have a dropdown menu that is filled by a mysql database. I need
I have a mysql table with a auto incremented key. I need a way
I have a table in mysql which is not normalized and I need to
I have an MSSQL database with LINQ to SQL . I have three tables.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.