Ask the Expert

Blocking inserts during procedure

I'm using SQL Server 2000. I want to write an INSERT procedure that:
  1. starts by blocking inserts on a table,
  2. selects rows on the same table and validates that an INSERT does not violate business rules,
  3. performs the insert,
  4. updates another table for a specific row (this update only occurs on an insert), and
  5. commits the transaction.
This INSERT procedure will be called by an ASP page, and I'm thinking that I should not have IIS create a connection per browser session. What is the best way to do this? How should I use TRANSACTION ISOLATION LEVEL and record locking to block inserts during the execution of the procedure?

    Requires Free Membership to View

Why do you want to block all inserts into a table when you are inserting another row into that table? This is a serious scalability problem and should only be used in very explicit situations and off the top of my head, I can't come up with a single application amongst the thousands of applications I've worked on that needed to lock an entire table from inserts.

As far as the code goes, I'll refer you to Books Online. This is nothing different than writing insert, update and select statements.

 

For More Information

This was first published in March 2003

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.