Pros: Allows data to be read (without blocking other transactions) and update data at a later time, ensuring that data has not been changed since the last time the data was read
When you use Updlock to read a record, you can add an update lock to the record that is fetched, and the record of the lock cannot be changed in other threads until the transaction at the end of the thread ends.
BEGIN Tran
SELECT * From address with (UPDLOCK) where [name]= ' Z '
WAITFOR DELAY ' 00:00:10 '
Update address set [name]= ' ZZ '
Commit Tran
Attention:
In another query:
If the lock is also updated, the current query is blocked until the other connection releases the update lock.
If the lock is not updated, the record of the update lock can be read directly.
This is a lock on the current row, not the entire table
The performance is severely affected if the entire table is locked
Update locks in SQL Server (UPDLOCK)