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

  • Home
  • SEARCH
  • 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 atomic function in C language, so that the process
I want to implement a simple script to do some boring housekeeping on my
I wrote small service class and I want implement something like that : service
I want to implement a minor file system like collection in MongoDB . So
I want to implement a mutex in Java using atomic variables. I tried implementing
I want to implement somethings like searching on wiki, when I want to search
I want to implement a splash screen in my application, like if the username
I Want Implement a Software by C#.net.I want Use a DataBase Manager Software like
i want implement geolocation notification like the app reminders. this is what i have
I want to implement caching of a list pulled from the db. I've had

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.