Solved

SQL 2005 - Insert Into (Foreign Key Issue).

Posted on 2009-06-30
10
560 Views
Last Modified: 2012-05-07
I think I have a Foreign Key issue and need some help on my insert.

Error Message recvd in application:

IDispatch error #3119
Number=547  State=23000  Source=Microsoft SQL Native Client
Description=The INSERT statement conflicted with the FOREIGN KEY constraint "FK_SC_ClearinghouseId". The conflict occurred in database "DemoCPS", table "dbo.Clearinghouse", column 'ClearinghouseId'.
Number=3621  State=01000  Source=Microsoft SQL Native Client
Description=The statement has been terminated.
Number=0  State=01000  Source=Microsoft SQL Native Client
Description=Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

INSERT  INTO dbo.Settings

        ( ClearinghouseId ,

          InsuranceCarrierCompanyId ,

          InsuranceCarrierCompanyProcessingId ,

          ECSInsuranceCarriersId ,

          PlugInId ,

          Type ,

          Name ,

          Value ,

          Created ,

          CreatedBy ,

          LastModified ,

          LastModifiedBy

        )

VALUES  ( 18 , -- ClearinghouseId - int

          NULL , -- InsuranceCarrierCompanyId - int

          NULL , -- InsuranceCarrierCompanyProcessingId - int

          NULL , -- ECSInsuranceCarriersId - int

          NULL , -- PlugInId - int

          'ClearinghouseTransmission' , -- Type - varchar(50)

          'AccountNumber' , -- Name - varchar(50)

          '13562' , -- Value - varchar(255)

          '2009-06-30 20:36:02' , -- Created - datetime

          'Jeff' , -- CreatedBy - varchar(30)

          '2009-06-30 20:36:02' , -- LastModified - datetime

          'Jeff'  -- LastModifiedBy - varchar(30)

        )

Open in new window

0
Comment
Question by:Jeff S
10 Comments
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 50 total points
ID: 24749545
this is because, you are trying to insert a value into the column whose value does not exists on 'ClearinghouseId' column
0
 
LVL 7

Author Comment

by:Jeff S
ID: 24749574
which value? I have a ClearinghouseId with that Id number.
0
 
LVL 39

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 50 total points
ID: 24749634
Please confirm you have the value 18 in whatever table FK_SC_ClearingHouseID is referenced from?
0
 
LVL 7

Author Comment

by:Jeff S
ID: 24749936
Yes, 18 exists. See attached screen shot.
6-30-2009-4-43-19-PM.pdf
0
 

Assisted Solution

by:turbohappy
turbohappy earned 50 total points
ID: 24750032
Can you get the text of the constraint FK_SC_ClearinghouseId ? Could be pointed to the wrong column on Settings or something silly like that.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 42

Accepted Solution

by:
EugeneZ earned 100 total points
ID: 24751259
you can try to disable  CONSTRAINTs

for example

ALTER TABLE Settings
 NOCHECK CONSTRAINT ALL

insert into Settings



ALTER TABLE Settings
 CHECK CONSTRAINT ALL


see more
Microsoft SQL Server Constraints
http://www.odetocode.com/Articles/79.aspx


0
 
LVL 23

Assisted Solution

by:Racim BOUDJAKDJI
Racim BOUDJAKDJI earned 100 total points
ID: 24752354
The error message seems to indicate that the broken constraint concerns the "dbo.Clearinghouse" table in column 'ClearinghouseId' not in Settings.   It seems the INSERT fails because there  is no parent key in the Clearinghouse table.  

Have you tried running

select * from dbo.Clearinghouse where ClearinghouseId = 18
0
 
LVL 14

Assisted Solution

by:Jagdish Devaku
Jagdish Devaku earned 100 total points
ID: 24752492
hi,
'ClearinghouseId' in 'Settings' tables is referred to 'ClearinghouseId' in 'Clearinghouse' table.
before inserting any value for 'ClearinghouseId'  in 'Settings' make sure that the value has an entry in 'ClearinghouseId'  in 'ClearingHouse' table.
if you dont have the value in 'ClearingHouse' table and trying to insert in 'Settings' table then only you will receive the above error.
so check it and fo the necessary.
bye.
0
 
LVL 2

Assisted Solution

by:kbac
kbac earned 50 total points
ID: 24753778
Can you check if you have the 18 in Settings table and if you have unique index checked in this constraint? You may have disabled multiple insertions.
0
 
LVL 7

Author Closing Comment

by:Jeff S
ID: 31598535
Split points to be fair.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now