I am working with SqlServer and Java.
I have the following (pseudo) code :
begin transaction
For each item of a list
select the row in db
...
update the row
End for
end transaction
Is it possible to have a deadlock in this situation if two transactions are running with the same items ?
My understanding is the following : For each item the select take a Shared lock on the row, and next the lock is upgraded to a Exclusive lock for the update. The lock are released at the end of the transaction. Is it true ? If yes I think that could explain a deadlock, if the first transaction tries to read a row locked by the second transaction that is trying to read a row already locked too, isn't it ?
Thks