With (nolock)

Source: Internet
Author: User

Disadvantages:

1. Dirty reads are generated.

2. Applicable only to select query statements

Advantages:

1. In some documents, the SQL query efficiency with (nolock) can be increased by 33%.

2. Can Be Used in inner join statements

Dirty read: A User modifies a resource. At this time, another user just reads the modified record. Then, the first user gives up the modification and the data is returned before the modification, the two different results are dirty reads.

Details:

To improve the query efficiency of SQL statements, we generally consider creating an index first. In fact, apart from index creation, when we run the SQL command, we add a section with (nolock) in the syntax) this improves the query performance by locking a dataset in a large online query environment.

Note that with (nolock) SQL select may cause dirty read (dirty read ).

For example:

Select Count (Userid)
From Employee With (Nolock)
Join Working_group With (Nolock)
On Employee. userid = Working_group.userid

In addition to simple select statements, the Select syntax with join statements can also be used. But the delete, insert, and update commands that require transaction will not work...

In some documents, the SQL query efficiency with (nolock) can be increased by 33%.
The with (nolock) Command tells SQL server that our SELECT command does not need to consider the current table's transaction lock status, so the efficiency will be significantly improved, in addition, the lock phenomenon of the database system will be significantly reduced (including dead lock ).

Yes
Note that with (nolock) does not consider the current table transaction.
Lock, so when some data is in multiple phase transactions (for example, transaction transactions across multiple tables --> such as a withdrawal system),
(Nolock) will ignore the data currently processing the transaction process...

In other words, when nolock is used, it allows users to read data that has been modified but has not been completed yet. Therefore, if you need to consider the real-time integrity of transaction data, use with (nolock) should be considered.

If you do not need to consider transaction, with (nolock) may be a useful reference.

NOTE 1: With (<table_hint>)
Specify the table scan, one or more indexes used by the query optimizer,
Or the query optimizer uses this data table and uses the lock mode for this statement.

NOTE 2: With (nolock) is equivalent to read uncommitted

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.