Update locks in SQL Server (UPDLOCK)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.