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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:38:28+00:00 2026-05-11T02:38:28+00:00

I want to implement an atomic transaction like the following: BEGIN TRAN A SELECT

  • 0

I want to implement an atomic transaction like the following:

BEGIN TRAN A  SELECT id FROM Inventory WITH (???) WHERE material_id = 25 AND quantity > 10  /* Process some things using the inventory record and eventually write some updates that are dependent on the fact that that specific inventory record had sufficient quantity (greater than 10). */  COMMIT TRAN A 

The problem is that there are other transactions happening that consume quantity from our inventory, so between the time that the record is selected and the updates are written in transaction A that record could become an invalid selection because it’s quantity might have been lowered below the threshold in the WHERE clause.

So the question is what locking hints should I use in the WITH clause to prevent the selected inventory record from being changed before I finish my updates and commit the transaction?

EDIT: So thanks to John, a good solution seems to be to set the transaction isolation level to REPEATABLE READ. This will will make sure that ‘no other transactions can modify data that has been read by the current transaction until the current transaction completes.’

  • 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. 2026-05-11T02:38:28+00:00Added an answer on May 11, 2026 at 2:38 am

    You may actually be better off setting the transaction isolation level rather than using a query hint.

    The following reference from Books Online provides details of each of the different Isolation levels.

    http://msdn.microsoft.com/en-us/library/ms173763.aspx

    Here is good article that explains the various types of locking behaviour in SQL Server and provides examples too.

    http://www.sqlteam.com/article/introduction-to-locking-in-sql-server

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement an ISAPI filter like feature using HttpModule in IIS7 running
For haskell practice I want to implement a game where students/pupils should learn some
I want to implement search functionality for a website (assume it is similar to
I want to implement an automatic update system for a windows application. Right now
I want to implement a paperless filing system and was looking to use WIA
I want to implement in Java a class for handling graph data structures. I
I want to implement a two-pass cache system: The first pass generates a PHP
I want to implement a simple debug log, which consists of a table into
I want to implement user stories in a new project where can i find
I want to implement forms authentication on an ASP.NET website, the site should seek

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.