<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Previously committed rows might be missed if NOLOCK hint is used</title><link>http://blogs.msdn.com/sqlcat/archive/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used.aspx</link><description>I received a question from one of our customers about using the NOLOCK hint: can it cause missing rows in scans even if the rows were committed well before my SELECT with NOLOCK starts? The NOLOCK hint is employed by many users to avoid contention on</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>SqlServerForum.org  &amp;raquo; Blog Archive   &amp;raquo; Previously committed rows might be missed if NOLOCK hint is used</title><link>http://blogs.msdn.com/sqlcat/archive/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used.aspx#1624850</link><pubDate>Thu, 08 Feb 2007 10:42:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1624850</guid><dc:creator>SqlServerForum.org  » Blog Archive   » Previously committed rows might be missed if NOLOCK hint is used</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://sqlserverforum.org/archives/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used/"&gt;http://sqlserverforum.org/archives/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Previously committed rows might be missed if NOLOCK hint is used</title><link>http://blogs.msdn.com/sqlcat/archive/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used.aspx#1660850</link><pubDate>Mon, 12 Feb 2007 16:14:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1660850</guid><dc:creator>DannyRa</dc:creator><description>&lt;p&gt;Hi lubor,we think we have managed to answer your challange &amp;nbsp;and repro a solution that demonstrates twice scanned rows :&lt;/p&gt;
&lt;p&gt;-- first create tables,index&lt;/p&gt;
&lt;p&gt;Create table DemoPageSplits (a int ,b varchar(6000))&lt;/p&gt;
&lt;p&gt;Create unique clustered index ix_clust on DemoPageSplits(a)&lt;/p&gt;
&lt;p&gt;Create table SaveInsertResults (Counter int,KeyValue int,InsTime datetime)&lt;/p&gt;
&lt;p&gt;-- fill the table&lt;/p&gt;
&lt;p&gt;TRUNCATE TABLE DemoPageSplits&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;set nocount on&lt;/p&gt;
&lt;p&gt;declare @i int ;&lt;/p&gt;
&lt;p&gt;set @i=1;&lt;/p&gt;
&lt;p&gt;while (@I&amp;lt;=10000)&lt;/p&gt;
&lt;p&gt;begin &lt;/p&gt;
&lt;p&gt;INSERT INTO DemoPageSplits VALUES (@I,'X')&lt;/p&gt;
&lt;p&gt;set @i=@i+1;&lt;/p&gt;
&lt;p&gt;end;&lt;/p&gt;
&lt;p&gt;-- RUN SCRIPT 2 and SCRIPT 3 in a sperate spid&lt;/p&gt;
&lt;p&gt;-- make sure you feed inside SCRIPT 3 the coorect spid of SCRIPT 2&lt;/p&gt;
&lt;p&gt;-- SCRIPT 2&lt;/p&gt;
&lt;p&gt;-- update the table and create page splits&lt;/p&gt;
&lt;p&gt;declare @imin int, @imax int;&lt;/p&gt;
&lt;p&gt;set @imin=1;&lt;/p&gt;
&lt;p&gt;set @imax=9999;&lt;/p&gt;
&lt;p&gt;While (@imax&amp;gt;@imin)&lt;/p&gt;
&lt;p&gt;begin&lt;/p&gt;
&lt;p&gt;update DemoPageSplits set b= replicate('x',6000)&lt;/p&gt;
&lt;p&gt;Where a=@imin&lt;/p&gt;
&lt;p&gt;update DemoPageSplits set b= replicate('y',6000)&lt;/p&gt;
&lt;p&gt;where a=@imAX&lt;/p&gt;
&lt;p&gt;set @imin=@imin+1;&lt;/p&gt;
&lt;p&gt;set @imax=@imax-1;&lt;/p&gt;
&lt;p&gt;end;&lt;/p&gt;
&lt;p&gt;--SCRIPT 3 &lt;/p&gt;
&lt;p&gt;--replace SPID= with the correct SPID of SCRIPT 2&lt;/p&gt;
&lt;p&gt;-- we make sure each insert has a specific id (counter)&lt;/p&gt;
&lt;p&gt;-- so we can determine if we get duplicate values from&lt;/p&gt;
&lt;p&gt;-- the same INSERT ... SELECT statment&lt;/p&gt;
&lt;p&gt;TRUNCATE TABLE SaveInsertResults&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;DECLARE @cnt INT&lt;/p&gt;
&lt;p&gt;SET @cnt=1&lt;/p&gt;
&lt;p&gt;WHILE EXISTS(SELECT STATUS FROM sys.sysprocesses&lt;/p&gt;
&lt;p&gt;WHERE SPID=(spid of script2 )AND STATUS&amp;lt;&amp;gt;'SLEEPING')&lt;/p&gt;
&lt;p&gt;BEGIN&lt;/p&gt;
&lt;p&gt;INSERT INTO SaveInsertResults &lt;/p&gt;
&lt;p&gt;SELECT @cnt,A,getdate() FROM DemoPageSplits (NOLOCK)&lt;/p&gt;
&lt;p&gt;SET @cnt=@cnt+1&lt;/p&gt;
&lt;p&gt;END&lt;/p&gt;
&lt;p&gt;--SCRIPT 4&lt;/p&gt;
&lt;p&gt;--- check the results&lt;/p&gt;
&lt;p&gt;-- &amp;nbsp;we just get the first occurance of having count more then 10000&lt;/p&gt;
&lt;p&gt;-- &amp;nbsp;create index just to make query run faster&lt;/p&gt;
&lt;p&gt;create clustered index inx_clust on SaveInsertResults(Counter,keyvalue,InsTime)&lt;/p&gt;
&lt;p&gt;-------------------------------------------------------&lt;/p&gt;
&lt;p&gt;SELECT Counter,KeyValue,InsTime,COUNT(*) CountDuplicates FROM SaveInsertResults&lt;/p&gt;
&lt;p&gt;WHERE Counter in (SELECT top 1 Counter FROM SaveInsertResults&lt;/p&gt;
&lt;p&gt;				 &amp;nbsp;GROUP BY Counter&lt;/p&gt;
&lt;p&gt;				 &amp;nbsp;HAVING COUNT(*)&amp;gt;10000&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;/p&gt;
&lt;p&gt;GROUP BY Counter,KeyValue,InsTime&lt;/p&gt;
&lt;p&gt;HAVING COUNT(*)&amp;gt;1&lt;/p&gt;
&lt;p&gt;partial results :&lt;/p&gt;
&lt;p&gt;Counter &amp;nbsp; &amp;nbsp; KeyValue &amp;nbsp; &amp;nbsp;InsTime &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CountDuplicates&lt;/p&gt;
&lt;p&gt;----------- ----------- ----------------------- ---------------&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;451 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;562 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;563 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;564 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;565 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;566 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;567 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;568 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;569 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;570 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;571 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;572 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;573 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;574 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;575 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;576 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;577 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;578 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;579 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;580 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;581 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;582 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;583 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;584 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;585 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;586 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;587 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2007-02-12 14:01:23.140 2&lt;/p&gt;
&lt;p&gt;......&lt;/p&gt;
&lt;p&gt;this show duplicate keys created in the destination table becasue of twice scanned rows.&lt;/p&gt;
&lt;p&gt;Uri Munitz &amp;amp;&lt;/p&gt;
&lt;p&gt;Danny Ravid&lt;/p&gt;
&lt;p&gt;Clalit Health Services&lt;/p&gt;
</description></item><item><title>re: Previously committed rows might be missed if NOLOCK hint is used</title><link>http://blogs.msdn.com/sqlcat/archive/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used.aspx#1811005</link><pubDate>Mon, 05 Mar 2007 20:06:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1811005</guid><dc:creator>LuborK</dc:creator><description>&lt;p&gt;Uri and Danny - your solution is correct and you will receive a book of your choice (handled separately in private mail). &lt;/p&gt;
&lt;p&gt;After posting my blog I was contactet by Itzik Ben-Gan who pointed me to his article in SQL Server magazine &lt;a rel="nofollow" target="_new" href="http://www.sqlmag.com/Articles/Index.cfm?ArticleID=92888&amp;amp;DisplayTab=Article"&gt;http://www.sqlmag.com/Articles/Index.cfm?ArticleID=92888&amp;amp;DisplayTab=Article&lt;/a&gt; where he provided solution to my problem even before I have posted my blog... I would like thank to Itzik for not spoiling this competition and let other try to come up with their own scripts to show the behavior!&lt;/p&gt;
</description></item><item><title>Query Failure with Read Uncommitted</title><link>http://blogs.msdn.com/sqlcat/archive/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used.aspx#3256116</link><pubDate>Tue, 12 Jun 2007 22:58:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3256116</guid><dc:creator>Craig Freedman's WebLog</dc:creator><description>&lt;p&gt;Over the past month or so, I've looked at pretty much every isolation level except for read uncommitted&lt;/p&gt;
</description></item><item><title>Isolation level read commited - linii duplicate</title><link>http://blogs.msdn.com/sqlcat/archive/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used.aspx#4510305</link><pubDate>Wed, 22 Aug 2007 16:26:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4510305</guid><dc:creator>Sql Server</dc:creator><description>&lt;p&gt;Isolation level read commited - linii duplicate&lt;/p&gt;
</description></item><item><title>SQL Spatial - Tips on Storage</title><link>http://blogs.msdn.com/sqlcat/archive/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used.aspx#9037107</link><pubDate>Tue, 04 Nov 2008 07:06:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9037107</guid><dc:creator>Dave does Data</dc:creator><description>&lt;p&gt;This post talks about talks about ways to Store Spatial Reference data in SQL in order to improve performance&lt;/p&gt;
</description></item><item><title>SQL Server Nolock Data Loss</title><link>http://blogs.msdn.com/sqlcat/archive/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used.aspx#9441851</link><pubDate>Tue, 24 Feb 2009 01:38:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9441851</guid><dc:creator>SQL and Tech in Africa</dc:creator><description>&lt;p&gt;I often get asked about the implications of using nolock query hints or read uncommitted and my response&lt;/p&gt;
</description></item><item><title>SQL Server NOLOCK Hint &amp; other poor ideas.</title><link>http://blogs.msdn.com/sqlcat/archive/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used.aspx#9532654</link><pubDate>Mon, 06 Apr 2009 02:40:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9532654</guid><dc:creator>Dave does Data</dc:creator><description>&lt;p&gt;Frequently I see production code, created by professional development teams, peppered with NOLOCK &amp;amp;amp;&lt;/p&gt;
</description></item></channel></rss>