title: Snapshot isolation transaction aborted due to update conflict
body: <p>Following statement:</p>
  
  <pre><code>INSERT INTO dbo.Changes([Content], [Date], [UserId], [CompanyId]) 
    VALUES (@1, @2, @3, @4);
  SELECT @@identity;
  </code></pre>
  
  <p>gives me this SQL error 3960:</p>
  
  <blockquote>
    <p>Snapshot isolation transaction aborted due to update conflict. You
    cannot use snapshot isolation to access table 'dbo.Companies' directly
    or indirectly in database 'myDatabase' to update, delete, or insert
    the row that has been modified or deleted by another transaction.
    Retry the transaction or change the isolation level for the
    update/delete statement.</p>
  </blockquote>
  
  <p>As far as I understood, from the error message, I should not update, delete, or insert to table <code>dbo.Companies</code> during the time another connection is modifying <code>dbo.Companies</code>. </p>
  
  <p>But why it occurs when I was inserting a new row to another table <code>dbo.Changes</code> (which has foreign key to <code>dbo.Companies</code>) and I was not deleting the referenced row in <code>dbo.Companies</code>, but I was just updating row in <code>dbo.Companies</code> and not the primary key? This should work ok, shouldn't it? (Is it a bug in SQL Server?)</p>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p>Tables looks like following:</p>
  
  <pre><code>dbo.Changes([Id] int PK, [Content] nvarchar, 
    [Date] datetime, [UserId] int, [CompanyId] int -&gt; dbo.Companies.[Id])
  dbo.Companies([Id] int PK, [Name] nvarchar)
  </code></pre>
  
  <p>Second update is doing:</p>
  
  <pre><code>UPDATE dbo.Companies WHERE [Id] = @1 SET [Name] = @2;
  </code></pre>