HomePHP Triggering Cascading Updates and Deletions with Foreign Key Constraints
Triggering Cascading Updates and Deletions with Foreign Key Constraints
Welcome to the final installment of a series on working with foreign key constraints in MySQL. With a respectable number of code samples, this series walks you through the basics of using foreign key constraints in MySQL tables and teaches you how to use them specifically for maintaining the integrity of relational databases.
And now that you've been introduced to the goal of this group of articles, itís time to refresh the topics that were covered in the last tutorial. In the penultimate part of the series, I showed you how to trigger the deletion in cascade of rows of a child MySQL table after performing the same operation on the records of its corresponding parent table.
In this example, the tables that I utilized to demonstrate how useful foreign key constraints can be comprised the database schema of a fictional blog program. It allowed some hypothetical users to post comments on a specific blog entry. Of course, the most relevant detail to stress here is that the cascading deletion of comments was triggered and handled internally by MySQL, in this way allowing you to implement a much simpler logic within the blog application.
Nevertheless, foreign key constraints allow you to handle both updates and deletions in the same MySQL table with the same ease, so in this final chapter of the series Iím going to explain how to achieve this by using the sample MySQL abstraction class coded in the preceding tutorial.
So, are ready to tackle the last chapter of this series on working with foreign key constraints in MySQL? Then start reading now!