SQL Server -- lock

Source: Internet
Author: User

1. updlock
It 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. When we use updlock to read records, we can add an update lock to the obtained records, in this way, the lock record cannot be changed in other threads and can only be changed after the transaction of this thread ends.

2. rowlock
Rowlock tells SQL Server to only use row-level locks. The rowlock syntax can be used in select, update, and delete statements. If a specified primary key exists in the update statement, the row-Level Lock is always triggered.

3. nolock
Nolock can ignore the lock and directly read data from the database. This means that the lock can be avoided to improve performance and scalability. But it also meansCodeThe possibility of an error exists. You may read uncommitted data that is being processed by the running transaction without verification. This risk can be quantified.

SQL Server supports more types of locks, such as tablock. SQL Server uses row-level locks, but often expands to page locks and table locks, resulting in deadlocks. In practical applications, you need to consider the concurrency of SQL operations, real-time requirements, table indexes, data distribution modes, and so on. Each lock type has its most suitable scenarios.

You can use management ---> activity monitor to analyze the lock snapshot information in the database.You can use the DBCC command to write lock-related information to the SQL server log for monitoring.

The following strange phenomena may occur in the process in the sushortded state:Http://www.windows-tech.info/15/fd219330fa8cb37a.php


 

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.