SQL query optimization

Source: Internet
Author: User

Debugging the following statement will find that the Slect statement without the plus (NOLOCK) will wait for the lock to be queried
BEGIN TRAN//Add and Subtract Tablockx (table Lock) When selected, SQL Server will place an exclusive lock on the entire table until the command or transaction ends. This prevents other processes from reading or modifying the data in the table.

SELECT * from Student holds shared locks, no waiting, shared
Update Student Set stuname = 66666 where stuid=1001

Rollback Tran

With (NOLOCK) 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 incomplete transaction (uncommited Transaction) or rollback (roll back), known as "dirty data."
SELECT * from Student with (NOLOCK)
The following will wait (the table lock) to release
SELECT * FROM Student

Specific View http://blog.csdn.net/jqrsdsy/article/details/19618931

SQL query optimization

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.