Two query-level hint-nolock and rowlock in SQL Server

Source: Internet
Author: User

You can use these two query-level hints to tell SQL Server how you want to deal with locking.

 

Nolock

================

When nolock is used, you will tell SQL Server to ignore locks and read data directly from the table. This means that you have avoided the SQL Server lock system and will greatly improve performance and scalability.

 

However, since you have completely bypassed the lock system, it means yourCodeThere is a risk of reading dirty data. You may be able to read illegal data that is not committed in a transaction. This is dangerous.

Rowlock

================

When rowlock is used, you will tell SQL Server to use only the row-Level Lock. you can use this keyword in select, update, and delete statements, but I only use it in update and delete statements.

 

You may think that when you specify the update of the primary key, a row lock will be triggered. however, when SQL server receives a batch processing with many such operations and many of these entries are in a page, you may sometimes see a page lock, in this case, a problem occurs. if you do not specify the primary key for update or delete, the database has no reason not to assume that many other things will not be affected. Therefore, it uses page lock directly, so bad things happen.

 

Source:

SQL Server locks

Http://www.developerfusion.com/article/1688/sql-server-locks/4/

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.