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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:12:17+00:00 2026-05-29T12:12:17+00:00

We have a complex Stored Procedure which first does INSERTS and then does UPDATES

  • 0

We have a complex Stored Procedure which first does INSERTS and then does UPDATES in a particular row. Ideally after completion of this request if user 2 hits the same SP and some SELECTS have to happen instead of UPDATES.
In case more than one requests come at the same time doing the first oepration, then we naturally get deadlocks on that UPDATE.

We are thinking of implementing WAITFOR such that the SP first sets a flag in a global temp table before starting and if a second request comes, it does waitfor some time to try again, so that after say 10 seconds, it can try again and if it sees that the update is done, it can skip completely to SELECT logic. This way we feel no user will get deadlock, after after say 5-10 seconds will get the results returned ultimately.

Is using WAITFOR like this fine or a DB architecture issue for some possible future issue?

  • 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-29T12:12:18+00:00Added an answer on May 29, 2026 at 12:12 pm

    This is a very risky idea, the database already has plenty of facilities to allow you to concurrently insert and update records. You can use transactions and hints to reduce the risk of deadlocks. Often improper indexing can lead to a large amount of deadlocks.

    Implementing a spinlock in a SQL proc is something that will generally go wrong.

    I blogged about some patterns you can use a while back: http://samsaffron.com/archive/2008/08/27/Deadlocked+

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

Sidebar

Related Questions

Using a stored procedure i have a fairly complex SQL statement which returns a
I have a fairly complex CLR stored procedure. What is the best way to
I have a complex sql query that I have in a stored procedure and
I have a Stored Procedure which executes some dynamic SQL. I want to use
I have a stored procedure which is erroring with Timeout expired. The code involved
I have a stored procedure that does something like: IF @Param = '1' SELECT
I have an existing database with lots of complex stored procedure and I want
I have a stored procedure which gets pivot fields as a parameter (say @P
I have a very simple stored procedure which returns multiple record sets. All of
I have a rather complex SELECT statement in a stored procedure that I am

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.