Error Code : 1216
Cannot add or update a child row: a foreign key
Error Code : 1217
Cannot delete or update a parent row: a foreign key
I have a parent table which has more than one child
table. When I catch the error in the programming
language, I would like to know
which table is giving the error because I want to
display the Message Box with the corresponding
message to the user, something like: "Cannot delete
customer because invoices exists."
Is there something in MySQL that can be able to tell
If there´s nothing to correct this, do you have an
idea to resolve this with something else?
since the mysql error message is not specific enough, you should run validation queries first to check that the intended operation is valid before doing an update/delete. that way you'll be able to present accurate messages to the user.
a select (read only) query should be no trouble. if the tables contain more that 200 records, starting thinking about using indexes if you have performance issues.
the thing is they are necessary from the application proint of view and should not be complex. to be safe, you could add a high level switch, using define(...), so that you can turn the extra validation off if the site has performance problems after introducing the change.