Solved

SQL 2005 - Insert Into (Foreign Key Issue).

Posted on 2009-06-30
10
569 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

751 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