Hi SudipBhatt-9737,
UPDATE dummy WITH (UPDLOCK, INDEX(TBLINDEX))
Please note that Index hints WITH INDEX(TBLINDEX) are only allowed in a FROM or OPTION clause, and cannot be used in the UPDATE statement.
If there is no index to locate the row to be locked, all the tested rows will be locked, and the lock on the qualified rows will be retained until the transaction is completed. But using indexes, SQL Server can quickly locate and lock only those rows that meet the conditions.
if i use UPDLOCK and ROWLOCK together then does this problem still happen means sql server will lock all rows instead of SSN=10 ?
Based on my test, without or with index, it seems there is no difference between using UPDLOCK , ROWLOCK together and using UPDLOCK alone.
Using UPDLOCK , ROWLOCK without index
Using UPDLOCK without index
Using UPDLOCK with clustered index
Using UPDLOCK , ROWLOCK with clustered index
Best Regards,
Amelia
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.