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. 

  • 相关阅读:
    20181022-JSP 开发环境搭建
    20181019-JSP 教程/简介
    20180829-Java多线程编程
    20180827(02)- Java发送邮件
    20180827-Java网络编程
    20180912-Java实例02
    docker安装redis
    springboot2集成swagger2出现guava包下的FluentIterable.append方法找不到
    Linux Centos7 网络设置UUID号的修改方法
    CentOS 7 主机名bogon解决办法
  • 原文地址:https://www.cnblogs.com/chucklu/p/14836407.html
Copyright © 2011-2022 走看看