Sql-server – How To Detect locking due to multi row updates

lockingsql server

Hi we are thinking of moving our updating records operations over from c# to sql, I am afraid of locking problems, how can I detect this problem if it occurs, and if it causes locking, is there any solution other then making small batches

Best Answer

we are thinking of moving our updating records operations over from c# to sql

Typically the performance benefits of multi-row DML outweigh any increased blocking. Plus you should be using transactions when performing a multi-row update from C#, in which case you'll have similar locking footprint to a server-side multi-row update: Every row updated will be locked until the transaction commits.

You don't want to monitor locking, you want to monitor blocking. And it's tracked in the system wait stats, session wait stats, and in query store wait stats, and with the good old Blocked Process Report.

See generally from the docs:

Transaction Locking and Row Versioning Guide

And from Brent Ozar:

Locking and Blocking in SQL Server

and

Implementing Snapshot or Read Committed Snapshot Isolation in SQL Server: A Guide