MySQL Foreign Key Constraints & Cascade Delete

I’ve never actually used a foreign key constraint with cascading delete in a production environment, least not that I can remember.

But for GPS Log this is very useful, to enforce key constraints, and also make deleting users extremely easy!  Just 1 delete statement on the UserId and the DB takes care of the rest.

This is a great post on where to find the foreign key feature in phpMyAdmin

His SQL to help fix the cases which voliate the key constraint is extremely useful:

(where ‘agenda’ is the table with the foreign key constraint referencing ‘meetings’)

SELECT * FROM `agenda` LEFT OUTER JOIN meetings on
agenda.meeting_id=meetings.meeting_id WHERE
meetings.meeting_id is NULL;

Leave a Reply

Your email address will not be published. Required fields are marked *