I'm trying to execute the following two queries in SQL Server Management Studio (in separate query windows). I run them in the same order I typed them here.
When isolation level is set to READ COMMITTED they execute ok, but when it's set to REPEATABLE READS the transactions are dead locked.
Can you please help me to understand what is dead locked here?
First:
begin tran declare @a int, @b int set @a = (select col1 from Test where id = 1) set @b = (select col1 from Test where id = 2) waitfor delay '00:00:10' update Test set col1 = @a + @b where id = 1 update Test set col1 = @a - @b where id = 2 commit Second:
begin tran update Test set col1 = -1 where id = 1 commit UPD Answer is laready given but folowing the advice I'm inserting the deadlock graph
