Home > Software engineering >  SQL Server reproduce locks LCK_M_U LCK_M_X LCK_M_IX
SQL Server reproduce locks LCK_M_U LCK_M_X LCK_M_IX

Time:01-24

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:

The LCK_M_IX enter image description here

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;

You can run enter image description here

Also, you may want to read Transaction locking and row versioning guide.

  • Related