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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:58:21+00:00 2026-05-23T22:58:21+00:00

I need to make the following sequence of steps in a sproc atomic. Here

  • 0

I need to make the following sequence of steps in a sproc atomic. Here is an approximate simplified example:

Customesrs table (CustomerId,..,OrderMax)
Products table (ProductId,…)
AvailableProducts view (ProductId and other properties)
Orders (CustomerId,OrderId)

  1. select @OrderMax from the Customers table
  2. select TOP @Ordermax from AvailableProducts view
  3. update some properties in the Products based on the result set of step 2
  4. insert orders into Orders table (based on the result set of step 2)
  5. return/select orders that were inserted

As I understand, there has to be a transaction on the whole thing and UPDLOCK. What has to be secured is Products table for update and Orders table for insert. However, the rows are queried from the view that is constructed from both of these tables.

What is the right way to make this sequence atomic and secure update and insert on the above tables?

  • 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-23T22:58:22+00:00Added an answer on May 23, 2026 at 10:58 pm

    Need to wrap all you logic in a Begin Transaction, Commit Transaction. The update / insert does not really care if the data came from a join unless it somehow created a situation where it could not roll back the transaction but it would have to get real messy to create a situation like that. If 3. and 4. have complex logic you may be forced into a cursor or .NET (but you can do some pretty complex logic with regular queries).

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

Sidebar

Related Questions

Following is the sample data. I need to make 3 copies of this data
I'd like to map the following sql in NHibernate. Will I need to make
I need to make to following snippet of code work in the context of
I need to make UI like following: In response to a HTTPRequest, I am
I'm using the following rule for my input: callback_validate_host I need to make the
I need to make a script that automates the following: Read comma or tab
We have following problem. Developers frequently need to make small changes to our web
I need to make a script that gets from the user the following: 1)
i need to make a group by clause with the following query: SELECT NAME,
I have a sequence of calls that I need to make, all of which

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.