{"id":6,"date":"2024-06-23T13:33:20","date_gmt":"2024-06-23T13:33:20","guid":{"rendered":"https:\/\/techobjects.net\/?p=6"},"modified":"2024-06-23T13:33:20","modified_gmt":"2024-06-23T13:33:20","slug":"sql-with-nolock-hint","status":"publish","type":"post","link":"https:\/\/techobjects.net\/?p=6","title":{"rendered":"SQL &#8211; With NoLock Hint"},"content":{"rendered":"\n<p>When running a query against a database that is highly available and records can be accessed at any time, I typically use the &#8220;with (NoLock)&#8221; hint in my SQL statements.<br><br>This ensures that if I&#8217;m accessing the same record as another user that we do not cause a deadlock. NoLock also runs slightly faster because it doesn&#8217;t have to acquire a lock on records.<br><br>However, note that when using NoLock that you will also be able to see transactions\/ records that have not been completed yet\/ committed. <br><br>Therefore, I don&#8217;t recommend using &#8220;with (NoLock)&#8221; in applications because you could end up getting uncommitted records. I do recommend using &#8220;with nolock&#8221; when you are just querying the database to check specific records in the table(s) to prevent accidently locking a record someone else\/ another application is attempting to access.<br><br><strong>Example:<\/strong><br><br>SELECT [Columns]<br>FROM [Table] with (nolock)<br>WHERE [condition]<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When running a query against a database that is highly available and records can be accessed at any time, I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[3],"tags":[10,4,9],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-sql","tag-nolock","tag-sql","tag-sql-hint"],"_links":{"self":[{"href":"https:\/\/techobjects.net\/index.php?rest_route=\/wp\/v2\/posts\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techobjects.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techobjects.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techobjects.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techobjects.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6"}],"version-history":[{"count":2,"href":"https:\/\/techobjects.net\/index.php?rest_route=\/wp\/v2\/posts\/6\/revisions"}],"predecessor-version":[{"id":25,"href":"https:\/\/techobjects.net\/index.php?rest_route=\/wp\/v2\/posts\/6\/revisions\/25"}],"wp:attachment":[{"href":"https:\/\/techobjects.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techobjects.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techobjects.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}