Remove bad child records to enable or create a foreign key in table
If you get "Parent Keys Not Found" error when you try to enable/create relation from a child table to the parent table, then you must identify and remove bad 'child' records.
The records can be identified and removed using the query:
DELETE FROM childtablename ct
WHERE NOT EXISTS (SELECT 'x' FROM parenttablename pt
WHERE ct.keycolumn1 = pt.keycolumn1 AND
ct.keycolumn2 = pt.keycolumn2...);
No comments:
Post a Comment