When does sql exclusively lock a row in an update statement?

Viewed 7047

Can a race condition occur in sql under these conditions?

If I have this SQL update running in one thread call it statement 1:

Update Items
Set Flag = B
where Flag = A;

And this SQL update running in another call it statement 2:

Update Items
Set Flag = C
where Flag = A;

Is it possible for each thread to read the same record where Flag is equal to A and write the record with their own values? Such that statement 1 can write it first and then statement 2 writes it or visa versa?

The answer to this question depends on when the database exclusively locks the update. Does it happen before it finds the records or after it finds the records and evaluates the where clause?

4 Answers
Related