views:

169

answers:

6

I am getting the following error. Could you please help me in ?

Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Sup_Item_Sup_Item_Cat". The conflict occurred in database "dev_bo", table "dbo.Sup_Item_Cat".
The statement has been terminated.


insert into sup_item (supplier_id,sup_item_id,name,sup_item_cat_id,status_code,last_modified_user_id,last_modified_timestamp,client_id) values(10162425,10,'jaiso','123123','a','12','2010-12-12','1062425')

the last coulum "client_id" i am getting the conflict. I tried to put the value which already exists in the dbo.Sup_Item_Cat to the column

corresponding to the sup_item.. but no joy :-(

+2  A: 

It means exactly what it says. You're trying to insert a value into a column that has a FK constraint on it that doesn't match any values in the lookup table.

Donnie
+2  A: 

You'll need to post your statement for more clarification. But...

That error means that the table you are inserting data into has a foreign key relationship with another table. Before data can be inserted, the value in the foreign key must field must exist in the other table first.

Justin Niessner
+2  A: 

In your table dbo.Sup_Item_Cat, it has a foreign key reference to another table. The way a FK works is it cannot have a value in that column that is not also in the primary key column of the referenced table.

If you have SQL Server Management Studio, open it up and sp_help 'dbo.dbo.Sup_Item_Cat'. See which column that FK is on, and which column of which table it references. You're inserting some bad data.

Let me know if you need anything explained better!

Mike M.
+2  A: 

You are trying to insert a record with a value in the foreign key column that doesn't exist in the foreign table.

For example: If you have Books and Authors tables where Books has a foreign key constraint on the Authors table and you try to insert a book record for which there is no author record.

By the way, a simple search on Google would have given you the answer...

Matthew Smith
please check my edited question
+2  A: 

The problem is not with client_id from what I can see. It looks more like the problem is with the 4th column, sup_item_cat_id

I would run

sp_helpconstraint sup_item

and pay attention to the constraint_keys column returned for the foreign key FK_Sup_Item_Sup_Item_Cat to confirm which column is the actual problem, but I am pretty sure it is not the one you are trying to fix. Besides '123123' looks suspect as well.

Cobusve
A: 

the primary key field will be populated by the system..so have to insert the rest of fields "withot the primary key field"...i tried it and t works.

moven