SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On



Working with Locks--Please Help Big Time Expand / Collapse
Author
Message
Posted Wednesday, September 30, 2009 8:49 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, October 28, 2009 6:33 PM
Points: 59, Visits: 138
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.
Post #796113
Posted Wednesday, September 30, 2009 11:24 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:30 PM
Points: 20,023, Visits: 13,596
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."

For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #796143
« Prev Topic | Next Topic »


Permissions Expand / Collapse