So what happens if I use it in all my update queries?
Like all hints, UPDLOCK
should only be used where there is a clear benefit.
How will it affect me negatively?
It depends on the query and the execution plan. Assuming you are only proposing to add UPDLOCK
to the target table, there may be no negative effects at all in very simple cases.
A "very simple case" is where all decisions about which rows qualify are made in a single plan operator. In this situation, update locks are only taken on rows that will definitely qualify, so no harm is done.
SQL Server automatically takes U
locks when searching for qualifying rows even without an UPDLOCK
hint, but only for the primary access method (e.g. an index seek and any associated RID or Key Lookup). These automatic U
locks are special, in that SQL Server can still release them early if later operators in the plan determine that the row does not qualify after all.
When UPDLOCK
is specified, any update locks taken cannot be released before the end of the transaction, even if other operators in the plan determine that the row does not actually qualify for the update. These extra U
locks reduce concurrency and may cause lock escalation to a table-exclusive lock.
For these reasons, it is generally not a good idea to specify UPLOCK
routinely on UPDATE
queries.
UPDLOCK
withUPDATE
should have no effect whatsoever; this is the default behaviour ofUPDATE
. I've only ever usedUPDLOCK
onSELECT
statements.