Note: The difference between a table that locks a database
SELECT * from table with (HOLDLOCK)
Other transactions can read the table, but cannot update the deletion
SELECT * from table with (TABLOCKX)
Other transactions cannot read tables, update and delete
Feature description of the lock options in the SELECT statement
SQL Server provides a powerful and complete lock mechanism to help achieve concurrency and high performance in database systems. Users can use the default settings of SQL Server or use the lock option in the SELECT statement to achieve the desired effect. This article describes the "lock options" and the corresponding feature descriptions in the SELECT statement.
Function Description:
NOLOCK (without lock)
When this option is selected, SQL Server does not add any locks when reading or modifying data. In this case, it is possible for the user to read the data in the unfinished transaction (uncommited Transaction) or rollback (Roll back), known as "dirty data."
HOLDLOCK (Keep Lock)
When this option is selected, SQL Server holds the shared lock until the end of the entire transaction and is not released on the way.
UPDLOCK (Modify Lock)
When this option is selected, SQL Server uses a modified lock to replace the shared lock when reading data and holds the lock to the end of the entire transaction or command. Use this option to ensure that multiple processes can read data at the same time, but only the process can modify the data.
TABLOCK (table Lock)
When this option is selected, SQL Server will place the shared lock on the entire table until the command ends. This option guarantees that other processes can read only and cannot modify the data.
Paglock (page lock)
This option is the default option, and SQL Server uses shared page locks when selected.
TABLOCKX (exclusive table lock)
When this option is selected, SQL Server locks up the entire table until the command or transaction ends. This prevents other processes from reading or modifying data in the table.
HOLDLOCK holds shared locks until the entire transaction completes and should be released immediately when the locked object is not needed, equal to the serializable transaction isolation level
NOLOCK statements do not emit shared locks, allow dirty reads, equal to READ UNCOMMITTED transaction isolation LEVEL
Paglock multiple page locks where a table lock is used
READPAST let SQL Server skip any locked rows, perform transactions, apply to READ UNCOMMITTED transaction isolation level only skip RID locks, do not skip pages, areas, and table locks
Rowlock force use of row locks
Tablockx enforces an exclusive table-level lock that prevents any other transaction from using this table during a transaction
Uplock force to use updates when reading tables without sharing locks
Note: The difference between a table that locks a database
SELECT * from table with (HOLDLOCK) Other transactions can read the table, but cannot update the deletion
SELECT * from table with (Tablockx) Other transactions cannot read tables, update and delete
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.