Msg 547, Level 16, State 0, Line 1 (help please)

I use this statements to do add a constraint or to add a foreign key.

USE Kudler1_FF ALTER TABLE Employee_Tbl ADD FOREIGN KEY (JobTitle) REFERENCE Job_Tbl (JobTitle) 

and this one:

Alter TABLE Employee_Tbl ADD Constraint FK_JobTitle FOREIGN KEY (JobTitle) REFERENCES Job_Tbl(JobTitle) 

but now I get this error:

Msg 547, Level 16, State 0, Line 1

The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_JobTitle". The conflict occurred in database "Kudler1_FF", table "dbo.Job_Tbl", column 'JobTitle'.

2

2 Answers

The table Employee_Tbl must be empty before you create the constraint or the foreign key because the database engine will validate the data present on this table. If the table already have some data that does not match with Job_Tbl, you will get the error message. Hope that helps.

You get this error while adding a record to a child table where that record is not present in the parent table. This happens while inserting the records.

Your problem is the same, you have already some records in the child table Employee that are not present in the parent table Job_Tbl

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like