I am trying to reproduce some kinds of locks on SQL Server database. I can easily reproduce LCK_M_U
when I create row and run in parallel many updates of this row.
Sometimes I could get LCK_M_X
when I am doing constantly selects, inserts and many updates of inserted row.
But I need to reproduce LCK_M_IX
so far no results. Any info how to reproduce it.
What is the reason and nature of generating LCK_M_IX
CodePudding user response:
Now, in separate query windows if we try to modify the data, we are going to be blocked as exclusive row cannot be set:
-- query window 2
BEGIN TRANSACTION;
UPDATE [dbo].[Documents]
SET [DocumentContent] = [DocumentContent] ' incorrect text'
WHERE [DocumentID] = 1;
--ROLLBACK TRANSACTION;
--COMMIT TRANSACTION;
Also, you may want to read Transaction locking and row versioning guide.