Updlock
The update lock is used when reading the table, instead of the shared lock, and the lock is kept until the statement or transaction ends. Updlock allows you to read data (without blocking other transactions) and update data later. It also ensures that the data has not been changed since the last read.
This is the description of the update lock in sqlserver2000.
When we use updlock to read records, we can add an update lock to the obtained records, therefore, the lock record cannot be changed in other threads and can only be changed after the transaction of the thread ends. For example:
Begin transaction -- start a transaction
Select Qty
From mytable with (updlock)
Where ID in (1, 2, 3)
Update mytable set qty = qty-A. Qty
From mytable as
Inner join @ _ table as B on A. ID = B. ID
Commit transaction -- submit a transaction
In this way, other threads or transactions cannot change the records whose IDs are 1, 2, and 3 before these statements are executed. other statements can be modified and read. values 1, 2, and 3 can only be read. If they are modified, they can only be operated after these statements are completed. this ensures that the data is correctly modified.