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. 

  • 相关阅读:
    R语言基础入门
    调用arcpy包批量进行矢量掩膜提取
    一些js面试高频知识点的总结
    js实现五子棋人机对战源码
    编程题汇总,持续更新
    颜色字符串转换
    根据包名,在指定空间中创建对象
    JavaScript中[]+[] 、[]+{}、{}+[]、{}+{}的结果分析
    CSS命名规范
    谈谈浏览器的兼容性
  • 原文地址:https://www.cnblogs.com/chucklu/p/14836407.html
Copyright © 2011-2022 走看看