SQL 2005 - Insert Into (Foreign Key Issue).

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 ,
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

Jeff SAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
this is because, you are trying to insert a value into the column whose value does not exists on 'ClearinghouseId' column
Jeff SAuthor Commented:
which value? I have a ClearinghouseId with that Id number.
Kyle AbrahamsSenior .Net DeveloperCommented:
Please confirm you have the value 18 in whatever table FK_SC_ClearingHouseID is referenced from?
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Jeff SAuthor Commented:
Yes, 18 exists. See attached screen shot.
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.
Eugene ZCommented:
you can try to disable  CONSTRAINTs

for example


insert into Settings


see more
Microsoft SQL Server Constraints


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Racim BOUDJAKDJIDatabase Architect - Dba - Data ScientistCommented:
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
Jagdish DevakuSr DB ArchitectCommented:
'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.
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.
Jeff SAuthor Commented:
Split points to be fair.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.