Working with Locks--Please Help Big Time

  • I have a stored procedure that updates a row. Here is the problem. A web form has text fields : name, born, died and populates each field with data from the database accordingly. When the update button is pressed it performs the stored procedure, thereby updating the info. But what if two people are on the form at the same time and see the same information. Person 1 changes the name only, but Person 2 changes the "born" only. Person 2 submits ahead of Person 1, thereby changing the "born" value to the newer value, but when Person 1 submits behind Person 2, the name updates, but the "born" will update back to the original date, thereby correcting Person 2's update.

    What can I do to make sure that person 1 doesn't overwrite person 2? How can I make sure each update is updated to the new value (i.e. the name gets Updated by Person 1, year born is also updated by Person 2 without them overwriting each other.)

    I read somewhere about locks, but I have no clue how to use them in this situation. Expert help is appreciated. And please explain clearly and a step by step approach. I am still rather new to advanced sql problems. Or if possible, direct me to an article.

    Any help would be greatly appreciated.

  • It's a big complicated subject with many options. Anything I would write here wouldn't be any better than what's in Books Online. I recommend looking up "row versioning [SQL Server]" (without the quotes) in Books Online where you can explore all the different methods to institute the proper locking mechanisms without making a table unusable or overwriting data in an undesirable manner.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply