I have a simple job which selects records, inserts them into another table and deletes them from the original table. I want the records to be locked even for reading so I used rowlock and xlock as table hints while selecting them. The thing is I can select said records while the transactions is working. Here's my code:set transaction isolation level repeatable read;gobegin try begin transaction; insert into myTable2 select * from myTable1 with(rowlock, xlock) where status = 1; waitfor delay '00:02:00'; delete from myTable1 where id in( select id from myTable1 with(rowlock, xlock) where status = 1 ); commit transaction;end trybegin catch if xact_state() <> 0 begin rollback transaction; endend catch;
While the transaction is waiting on WAITFOR line, I can still select the records in another connection. What am I doing wrong?