Monday, March 26, 2012

Newbie Question

Hello,
A very simple question:
What happens when two people work at the same time in the same record?
The Last win or the first?It depends on the configuration of your database, what your
application/component is doing in background, what you have
done before starting with the update ...
Normaly you use "optimistic locking", which means you do not
lock the record when you read it or when you start to change it.
The record will only be locked for the short time of writing the
new data in the database.
Now when somebody has changed the same record there could
be two options:
a) your database/component checks that the record was changed
in the meantime and gives an error
b) your database/component only checks if one of the fields you
have changed where changed by another user.
For example: your record holds person number and name
you read the record and change the number, in the meantime
somebody has changed the name. When you write your change
into the database so it only checks if number is like before. This is
because the other user only changed the name. Your update now
only changes the number and when you read the record again you
will see your new number and the new name.
But there are a lot more possibilities, you should read a good book
about transactions and locking mechanism and do tests, test, tests, ...
Another way would be "pessimistic locking" where you read a record
again with locking if the state goes to editing or to lock when you are
reading the record and if locking is okay you can be sure that your
changes can be written and nobody else can change something in the
meantime. But the bad thing is that the record stays still locked if
somebody started editing and then goes to luch before saving the
changes.

bye,
Helmut|||Thanks Helmut
for this full Description.
I will test some scenarios and think I take the last option with the locked records.
Bye Martin

No comments:

Post a Comment