0

Not quite sure whether this is a question for the server side programming forum or for SQL forum. Nevertheless, here it is:

What is the best way to update a record when 2 users of my site happen to edit it simultaneously?

For example, assume the following scenario:
Let's say users John Doe and Jane Doe log into my site and happen to view the below record simultaneously.
---------------------------------------------------------------------------------
Bruce Wayne | Gotham City | (910)000-0000
---------------------------------------------------------------------------------
If John edits the above phone number to (910)000-0001 and Jane changes it to (910)000-0002 - at the same time - what value do I update the DB with?

And how do I prevent users overwriting each others' updates?

Thanks!

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by sknake
0

This is a design choice. I personally let the last person to make the change overwrite the other persons data. If you use a DataSet in .NET generated code it has an option for optimisitic concurrency where you can tell it to throw an exception if someone has modified the data since you last retrieved it.

This also goes to show why it is important to only push the changed fields to the SQL server and not everything.

My school of thought is: Two people have two different phone numbers for the same person, different from the one it is now. If Jane changes and then John sees it, he will still change it anyway with his phone number because 'he is right.' This will upset Jane because she was right. They will then have a standoff in the office hallway.

If they're going to modify the data they are going to overwrite it regardless of what it is, if it does not match their value. This is not true in all cases but I feel it is a safe assumption.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.