title: Why is SQL Server 2008 blocking SELECT's on long transaction INSERT's?
body: <p>We are trying to have a transactional table that only takes new records inserted on a regular basis.</p>
  
  <p>This simple table requires us to continuously add new records to it over time.  The volume of transactions into this table is expected to be quite high, and also there might be periodical batch imports of transactions (>1000) that may take multiple seconds to complete.</p>
  
  <p>From this data we then do a set of select statements grouping different columns to return the required values.</p>
  
  <p>From our initial testing we have found a bottleneck to be related to SQL Server that blocks our SELECT's when in the middle of a transaction of INSERTS.</p>
  
  <p>Below is a simple example that can be run to illustrate the problem.</p>
  
  <p>-- Simple DB Table</p>
  
  <pre><code>create table LOCK_TEST (
  LOCK_TEST_ID int identity ,
  AMOUNT int);
  </code></pre>
  
  <p>-- Run this in 1 query window</p>
  
  <pre><code>begin tran
  insert into LOCK_TEST (AMOUNT) values (1);
  WAITFOR DELAY '00:00:15' ---- 15 Second Delay
  insert into LOCK_TEST (AMOUNT) values (1);
  commit
  </code></pre>
  
  <p>-- In Query 2 run this in parallel</p>
  
  <pre><code>select SUM(AMOUNT)
  from LOCK_TEST;
  </code></pre>
  
  <p>I would expect Query 2 to return straight away, with 0 until query 1 completes, and then show 2.  We never want to see 1 returned from the 2nd query.</p>
  
  <p>The answer's we have looked at relate to WITH (NOLOCK) on the select statement.  But this violates the transactional boundaries, and the returned information may be financial in nature and we don't wish to see any uncommited details in our queries.</p>
  
  <p>My problem seems to be on the INSERT side...<br>
  <strong>Why does the INSERT block the SELECT statement even though it's not modifying any existing data?</strong></p>
  
  <p><strong>Bonus points question:</strong>  Is this a "feature" of SQL Server, or would we find this on other Database flavours also?</p>
  
  <p><strong>UPDATE</strong>
  I have now had time to find a local oracle database and run the same simple test.  This test pass's as I would expect.</p>
  
  <p>Ie I can run query as often as I want, and it will return null until the 1st transaction commits, then returns 2.</p>
  
  <p><strong>Is there a way to make SQL Server work like this? or do we need to move to Oracle?</strong></p>