I’m trying to create a query that will update the value of rgn_no and chp_cd within the table bue to the values of rgn_no and chp_cd within the table chapterassociation. I don’t think the WHERE clause is any problems, but I’m getting the following error when I run it in:
SQL error:
ERROR: insert or update on table "bue" violates foreign key constraint "bue_chp_cd_fkey"
DETAIL: Key (chp_cd)=(CA3) is not present in table "chapter".
Any assistance is greatly appreciated!
SQL Query:
UPDATE bue SET
rgn_no = chapterassociation.rgn_no,
chp_cd = chapterassociation.chp_cd
FROM
chapterassociation
WHERE
bue.mbr_no IS NULL AND bue.chp_cd IS NULL
AND bue.work_state = chapterassociation.work_state
AND bue.bgu_cd = chapterassociation.bgu_cd
Read the error message:
It says that one of your updates wants to set chp_cd to ‘CA3’, but that CA3 is not an allowed value, because a foreign key constraint wants the value ‘CA3″ to be present in the table “chapter”. That’s all.
There is nothing wrong with your query’s syntax, it is just the fact that your query would cause the data to conflict with a constraint in the data model.