Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9010475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:28:12+00:00 2026-06-16T02:28:12+00:00

Following statement: INSERT INTO dbo.Changes([Content], [Date], [UserId], [CompanyId]) VALUES (@1, @2, @3, @4); SELECT

  • 0

Following statement:

INSERT INTO dbo.Changes([Content], [Date], [UserId], [CompanyId]) 
  VALUES (@1, @2, @3, @4);
SELECT @@identity;

gives me this SQL error 3960:

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.

As far as I understood, from the error message, I should not update, delete, or insert to table dbo.Companies during the time another connection is modifying dbo.Companies.

But why it occurs when I was inserting a new row to another table dbo.Changes (which has foreign key to dbo.Companies) and I was not deleting the referenced row in dbo.Companies, but I was just updating row in dbo.Companies and not the primary key? This should work ok, shouldn’t it? (Is it a bug in SQL Server?)

UPDATE:

Tables looks like following:

dbo.Changes([Id] int PK, [Content] nvarchar, 
  [Date] datetime, [UserId] int, [CompanyId] int -> dbo.Companies.[Id])
dbo.Companies([Id] int PK, [Name] nvarchar)

Second update is doing:

UPDATE dbo.Companies WHERE [Id] = @1 SET [Name] = @2;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:28:14+00:00Added an answer on June 16, 2026 at 2:28 am

    It appears SQL Server will acquire update locks on any record it has to read even if it doesn’t modify it.

    More info on this microsoft.public.sqlserver.server thread:

    Without a supporting index on CustomerContactPerson, the statement

    DELETE FROM ContactPerson WHERE ID = @ID;

    Will require a “current”
    read of all the rows in CustomerContactPerson to ensure that there
    are no CustomerContactPerson rows that refer to the deleted
    ContactPerson row. With the index, the DELETE can determine that
    there are no related rows in CustomerContactPerson without reading the
    rows affected by the other transaction.

    Additionally, in a snapshot
    transaction the pattern for reading data which you are going to turn
    around and update is to take an UPDLOCK when you read. This ensures
    that you are making your update on the basis of “current” data, not
    “consistent” (snapshot) data, and that when you issue the DML, it the
    data won’t be locked, and you won’t unwittingly overwrite another
    session’s change.

    The fix for us was adding indexes to the foreign keys

    In your example, I suspect adding an index to Changes.CompanyId will help. I’m not sure if this is a real solution. Can the SQL Server optimizer choose not to use the index?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following SQL insert statement. insert into [dbo].[Lookup] (XMLField) select '<root>' +
I have the following INSERT statement: INSERT INTO [StoreTestDB].[dbo].[KitItem] ([KitItemGUID] ,[KitGroupID] ,[Name] ,[Description] ,[PriceDelta]
INSERT INTO dbo.VehiclesCategories ( VehicleId, CategoryId ) VALUES ( t1.ID , t2.ID) SELECT t1.ID,
This is trying to insert null into Comment.BlogArticleID. The following GenericADOException appeared: could not
I'm trying to run the following statement: INSERT INTO table ( as, ad ,af,
I am getting the following error when I am executing the following statement INSERT
I have the following insert statement in my execute sql task in SSIS: INSERT
What i wannt is something like this: SELECT * FROM [dbo].[UNIONTABLE1] UNION SELECT *
The following sproc attempts to insert a row into a table and generate a
In the following t-sql statement, how many times will the dbo.FUNC function get called?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.