Way to check for foreign key references before deleting in MySQL?
- by Chad Johnson
I'm working with a content management system, and users are prompted with a confirmation screen before deleting records. Some records are foreign key referenced in other tables, and therefore they cannot be deleted.
I would like to display a message beside a given record if it has foreign key references. To know whether I should display the message for a record, I could just query the referencing table and see if there are references. But the problem is, there are about a dozen tables with records potentially referencing this record, and a lookup could take a "long" time.
Is there an easy way to tell whether the record is delete-ready (ie. has no foreign key references)?