It’s depends on the update logic whether or how often a deadlock can occur. But your code should recover from a deadlock as it is an expected response.
Avoiding table locking while Update
Hi Team,
I am working on a SQL Server Stored Procedure, where I need to update a column of a table in a no. of rows.
This stored procedure will be called from a timer trigger Azure function, which will scale so that 2 function instances may call the stored procedure at same time and work on same same rows. Please let me know how should I write the update statement so that I do not face any table locking issue in the future.
Please let me know if any other detail is needed.
Thanks,
Salil
SQL Server Transact-SQL
2 answers
Sort by: Oldest
-
Bruce (SqlWork.com) 77,476 Reputation points Volunteer Moderator
2025-05-21T18:34:29.45+00:00 -
Erland Sommarskog 121.3K Reputation points MVP Volunteer Moderator
2025-05-21T21:08:08.3833333+00:00 First of all, there should be an index that supports the WHERE clause in your UPDATE statement.
Next, the conditions in the WHERE clause should not entangle the indexed column in any expressions, as that is likely to render the index less useful.