SQL Server – Force Update Statements to Take Page Locks in the Same Order

deadlocklockingsql serversql server 2014

I have two update statements on the same table that take page locks in different orders. This leads to deadlocks.

  • Process A owns an update lock on page 1, and requests an update lock on
    page 2.
  • Process B owns an update lock on page 2, and wants an update
    lock on page 1.

How can I force both statements to take page locks in the same order?

Best Answer

How can I force both statements to take page locks in the same order?

You can't. Instead force them both to take a table lock with a TABLOCKX hint, or use an Application Lock to serialize the sessions.