Solved

SQL 2005 - Insert Into (Foreign Key Issue).

Posted on 2009-06-30
10
570 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 40

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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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
 
LVL 43

Accepted Solution

by:
Eugene Z 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

617 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