The INSERT statement conflicted with the FOREIGN KEY constraint with column id code example

Example 1: sqlexception: the insert statement conflicted with the foreign key constraint

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.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!

Example 2: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "". The conflict occurred in database "", table ", column

SELECT *
FROM [rpt].ReportLessonCompetency rlc
WHERE NOT EXISTS
(
    SELECT 1 
    FROM [rpt].TraineeGrade tg
    WHERE tg.Id = rlc.Grade
)

Tags:

Misc Example