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 980939
In Process

The Archive Base Latest Questions

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

edit: SQL Server 2005 I have a customer application running on 5 separate servers.

  • 0

edit: SQL Server 2005

I have a customer application running on 5 separate servers. Each application is looking at a single scheduling table. I want to be sure that no machine can access the same record at the same time as any other machine. Each server is capable of processing 1 row only at a time. Basically, the application just selects the next record available that can be run. If nothing is selected, it simply does nothing and waits another minute and tries again.

[edit: To be more specific, no row is ever deleted from dbo.the_table. It simply marks IsProcessing=1 so that other machines will not pick that up]

My stored procedure (SQL Server) is as followed:

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRAN

SET @ScheduleId = SELECT TOP 1 ScheduleId FROM dbo.the_table WHERE NextRun <= GETDATE() AND IsEnabled = 1

UPDATE dbo.the_table SET IsProcessing=1 WHERE ScheduleId = @ScheduleId

--Edit: Return this to the program so we can do stuff with the data
SELECT * FROM dbo.the_table WHERE ScheduleId = @ScheduleId

IF @@ERROR = 0
COMMIT TRAN
ELSE
ROLLBACK TRAN

I want to be certain that the while the transaction is in progress, any SELECT statement by the other machines will be blocked until the transaction is committed by the blocking transaction. (e.g., Machine A starts a transaction — if B,C,D, or E try and SELECT, they will wait until the transaction is committed).

  • 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-16T04:27:52+00:00Added an answer on May 16, 2026 at 4:27 am

    What version of SQL Server are you on? If SQL2005+ you could do this all in one statement

    ;WITH s AS
    (
    SELECT TOP 1 * 
    FROM dbo.the_table WHERE NextRun <= GETDATE() AND IsEnabled = 1
    AND IsProcessing = 0 /*?*/
    --ORDER BY ScheduleId  ?
    )
    UPDATE    s  WITH (ROWLOCK, READPAST)
    SET     IsProcessing=1 
    OUTPUT INSERTED.*  /*Return row that was updated*/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two database servers running SQL Server 2005 Enterprise that I want to
I have a table in SQL Server 2005 with a variable number of columns,
I have a table in sql server 2005 which holds an ip range and
I have a database table in SQL Server 2005 Express that takes in 2367
Edit: using SQL Server 2005. I have a query that has to check whether
Using MS SQL Server 2005. On one of our servers we're running out of
I have two tables (MS SQL Server 2005) with an existing application (no DB
I have a SQL Server 2005 database that stores data for multiple users. Each
i have a char(10) column in a table in a SQL-Server 2005 database: CREATE
I have this table in sql server 2005: id student active 1 Bob 1

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.