Way to check for foreign key references before deleting in MySQL?
Posted
by Chad Johnson
on Stack Overflow
See other posts from Stack Overflow
or by Chad Johnson
Published on 2010-04-26T23:21:35Z
Indexed on
2010/04/26
23:23 UTC
Read the original article
Hit count: 177
mysql
|foreign-keys
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)?
© Stack Overflow or respective owner