Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
SQL Server 2005 General Discussion
»
The INSERT statement conflicted with the...
The INSERT statement conflicted with the FOREIGN KEY constraint(Not reproducible)
Rate Topic
Display Mode
Topic Options
Author
Message
anki_bakshi
anki_bakshi
Posted Friday, August 14, 2009 3:59 PM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, January 05, 2010 5:37 PM
Points: 8,
Visits: 30
We have one parent table:
Document (GID int identity(1,1),ParentName)
and two child tables, both having FOREIGN KEY(Document_GID) REFERENCES Document (GID)
1. DocumentChild1(Document_GID,Child1_name)
2. DocumentChild2(Document_GID,Child2_name)
Steps:
1. Lets say DocumentChild1 table has 'n' documents.
2. Then in a transaction we try to insert entries into DocumentChild2 from DocumentChild1.
Here, we get foreign key violation :
The INSERT statement conflicted with the FOREIGN KEY constraint "DocumentChild2_DOC_GID_FK".
The conflict occurred in database "VOL_ABC", table "Document", column 'GID'.
Also, we don't have any delete operation in Document table. But many insert operation into this table can be going on in parallel.
We saw this error once. Everything works fine when we reran the insert sql.
I am wondering, what could have caused this behavior. Definitely data exists in the Document table else insert into DocumentChild1 would have failed.
Let me know if you need more details.
Post #771369
Jack Corbett
Jack Corbett
Posted Monday, August 17, 2009 6:41 AM
SSChampion
Group: General Forum Members
Last Login: Yesterday @ 3:27 PM
Points: 10,100,
Visits: 11,159
You aren't using nolock or SET ISOLATION LEVEL READ UNCOMMITTED are you?
Jack Corbett
Applications Developer
Don't let the good be the enemy of the best. --
Paul Fleming
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #771848
anki_bakshi
anki_bakshi
Posted Monday, August 17, 2009 2:11 PM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, January 05, 2010 5:37 PM
Points: 8,
Visits: 30
My transaction isolation level is READ_COMMITTED and yes, I am using nolocks while reading data from DocumentChild1. But, I have verified that no one is changing(Insert/Update/Delete) data in the DocumentChild1 during that time. Also, I had sql profiler enable when we saw this error. The rowcount suggests that the correct number of records being read from DocumentChild1.
Thanks for your help.
Post #772248
anki_bakshi
anki_bakshi
Posted Monday, August 17, 2009 2:41 PM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, January 05, 2010 5:37 PM
Points: 8,
Visits: 30
I am wondering do indexes on the table play part in this FK constraint violation error.
I have a unique index on DocumentChild2(Document_GID,Child2_name).
Post #772273
Jack Corbett
Jack Corbett
Posted Monday, August 17, 2009 2:59 PM
SSChampion
Group: General Forum Members
Last Login: Yesterday @ 3:27 PM
Points: 10,100,
Visits: 11,159
anki_bakshi (8/17/2009)
I am wondering do indexes on the table play part in this FK constraint violation error.
I have a unique index on DocumentChild2(Document_GID,Child2_name).
Nope, you'd get a unique index/constraint violation error.
Was the FK on DocumentChild1 created AFTER there was data in the table? If to there could be "bad" data in the table if the constraint was created with the NOCHECK option
Jack Corbett
Applications Developer
Don't let the good be the enemy of the best. --
Paul Fleming
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #772291
anki_bakshi
anki_bakshi
Posted Monday, August 17, 2009 5:44 PM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, January 05, 2010 5:37 PM
Points: 8,
Visits: 30
No, the FK on DocumentChild1 was created at the time of table creation.
Can multiple asynchronous inserts in the Document table can cause this behavior? I mean may be the index page where the concerned GID is located is locked by the Insert sql as it is also inserting into the same page.
Post #772374
anki_bakshi
anki_bakshi
Posted Wednesday, August 19, 2009 12:14 PM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, January 05, 2010 5:37 PM
Points: 8,
Visits: 30
Update:
We had a live meeting session with microsoft support where they have debugged this behavior. There is no resolution yet, and might be a bug on their side.
Post #773804
anki_bakshi
anki_bakshi
Posted Wednesday, October 28, 2009 11:57 AM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, January 05, 2010 5:37 PM
Points: 8,
Visits: 30
Update: There is a bug in microsoft sql server's Hash Map join plan when it comes to # based temp tables.
To suppress this error(workaround given by Microsoft team): Include order by 1 clause - this will change the join plan.
For eg.
INSERT INTO MAIN_TABLE (DOC_ID_FK_TO_SOME_OTHER_TABLE, ANY_COLUMN)
SELECT DOC_ID_FK_TO_SOME_OTHER_TABLE, ANY_COLUMN
FROM #TEMP_TABLE -- This will sometimes throw FK violation which is not a --valid violation
ORDER BY 1 -- This suppresses the error
Post #810184
Jack Corbett
Jack Corbett
Posted Wednesday, October 28, 2009 12:01 PM
SSChampion
Group: General Forum Members
Last Login: Yesterday @ 3:27 PM
Points: 10,100,
Visits: 11,159
Interesting. Thanks for posting the resolution even though it came months later.
Jack Corbett
Applications Developer
Don't let the good be the enemy of the best. --
Paul Fleming
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #810192
anki_bakshi
anki_bakshi
Posted Tuesday, January 05, 2010 5:39 PM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, January 05, 2010 5:37 PM
Points: 8,
Visits: 30
Here is KB article ( http://support.microsoft.com/kb/977100/ )explaining about the issue we have raised and possible workarounds in case anyone is interested.
Post #842507
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.