zoukankan      html  css  js  c++  java
  • Understanding the Impact of NOLOCK and WITH NOLOCK Table Hints in SQL Server

    Understanding the Impact of NOLOCK and WITH NOLOCK Table Hints in SQL Server

    Every once in a while, SQL Server database administrators find themselves in disagreements with their application developer counterparts – particularly when it comes to some of the latter’s Transact SQL (T-SQL) developmental practices. One of my first observations when I joined my current employer is that almost all T-SQL scripts written by application developers uses the NOLOCK table hint. However, from the interactions that I have had with these esteemed developers it doesn’t seem like they understand how the NOLOCK table hint works. Furthermore, although they seem to be aware of a distinction between NOLOCK and the WITH NOLOCK table hint, they again do not seem to comprehend how the two differ from one another. In this article, I explore the internal workings of the NOLOCK table hint and examine the implications of omitting the WITH keyword. 

    Understanding NOLOCK Hint

    The default behaviour in SQL Server is for every query to acquire its own shared lock prior to reading data from a given table. This behaviour ensures that you are only reading committed data. However, the NOLOCK table hint allows you to instruct the query optimiser to read a given table without obtaining an exclusive or shared lock. The benefits of querying data using the NOLOCK table hint is that it requires less memory and prevents deadlocks from occurring with any other queries that may be reading similar data. The only drawback is that using the NOLOCK table hint may accidentally result into reading uncommitted “dirty” data. In the following sections, I will provide practical examples for using NOLOCK and WITH NOLOCK table hints. 

  • 相关阅读:
    JDK 1.7.0 安装后,如何配置,以及如何打开JAR文件
    C++中的内存!(转载)堆 栈 全局/static变量区 常量区
    学习.net应该知道什么
    SQL Group By
    编码
    ASP生成静态Html文件技术杂谈
    如何写出优秀的ASP应用
    DropDownList的绑定方法
    如何提高WEB程序的效率
    什么才是提高ASP性能的最佳选择
  • 原文地址:https://www.cnblogs.com/chucklu/p/14836407.html
Copyright © 2011-2022 走看看