• 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. 

  • 相关阅读:
    GateWay程序分析02_IAP_FLASH.H
    GateWay程序分析05_WDT.h
    GateWay程序分析03_timer.h
    GateWay程序分析_主函数_02整体流程
    网关系统软件设计_系统需求分析v1
    [收藏]DIV中图片居中
    CSS HACK 手记
    一道题“谁养鱼”的穷举解法。
    简单好用的联动下拉控件(修正)
    权限认证的WEB页面实施
  • 原文地址:https://www.cnblogs.com/chucklu/p/14836407.html
Copyright © 2020-2023  润新知