Avoiding table locking while Update

Salil Singh 60 Reputation points
2025-05-21T18:29:31.7566667+00:00

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 SQL Server Transact-SQL
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2025-05-21T18:34:29.45+00:00

    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.


  2. Erland Sommarskog 121.4K 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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.