Table-level locks provided by sqlserver

Source: Internet
Author: User
The table-level locks specified by sqlserver are displayed as follows: 1. HOLDLOCK: Keep the shared lock on the table until the entire transaction ends, instead of releasing the added lock immediately after the statement is executed. 2. NOLOCK: no shared or exclusive locks are added. When this option takes effect, it may read uncommitted data or "dirty data". This option is only applicable

The table-level locks specified by sqlserver are displayed as follows: 1. HOLDLOCK: Keep the shared lock on the table until the entire transaction ends, instead of releasing the added lock immediately after the statement is executed. 2. NOLOCK: no shared or exclusive locks are added. When this option takes effect, it may read uncommitted data or "dirty data". This option is only applicable

The table-level locking tips specified by sqlserver are as follows:

1. HOLDLOCK: Keep the shared lock on the table until the entire transaction ends, instead of releasing the added lock immediately after the statement is executed.

2. NOLOCK: no shared or exclusive locks are added. When this option takes effect, uncommitted data or "dirty data" may be read. This option is only applicable to SELECT statements.

3. PAGLOCK: Specify to add a page lock (otherwise, a table lock may be added)

4. READCOMMITTED performs scanning with the same lock semantics as transactions running at the committed read isolation level. By default, SQL Server 2000 operates at this isolation level.

5. READPAST: Skip the data rows that have been locked. This option will allow the transaction to skip the data rows that have been locked by other transactions when reading data, rather than blocking until other transactions release the lock, READPAST is only applicable to SELECT statement operations in transaction operations at the read committed isolation level.

6. READUNCOMMITTED: equivalent to NOLOCK.

7. REPEATABLEREAD: Set the transaction to a read-only isolation level.

8. ROWLOCK: Use row-level locks instead of coarse-grained page-level locks and table-level locks.

9. SERIALIZABLE: scan with the same lock semantics as transactions running at the SERIALIZABLE read isolation level. Equivalent to HOLDLOCK.

10. TABLOCK: Table-level locks are used instead of Row-level or page-level locks. After the statement is executed, SQL Server releases the lock. If both HOLDLOCK is specified, the lock remains until the transaction ends.

11. TABLOCKX: Specifies the use of the exclusive lock on the table. This lock can prevent other transactions from reading or updating data in the table until the statement or the entire transaction ends.

12. UPDLOCK: Specify the update lock when reading data in the table, instead of the shared lock. The lock remains until this statement or the entire transaction ends, UPDLOCK is used to allow users to read data first (without blocking other users from reading data), and ensure that the data is not modified by other users during this period of time when the data is updated later.

SELECT * FROM table WITH (HOLDLOCK) other transactions can read the table, but cannot update or delete the table.

SELECT * FROM table WITH (TABLOCKX) other transactions cannot read, update, and delete tables.

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.