Updating foreign key
In addition, you can set up a cascade on delete action for the table, all the orders associated with the customer are also deleted.This saves you time and efforts of using multiple DELETE statements or a DELETE JOIN statement.We have a specific tutorial on the self-join to help you query data against this kind of table. Foreign keys enforce referential integrity that helps you maintain the consistency and integrity of the data automatically.For example, you cannot create an order for a non-existent customer.A row in the child table must contain values that exist in the parent table e.g., each order record in the table.Multiple orders can refer to the same customer therefore, this relationship is called one (customer) to many (orders), or one-to-many.Sometimes, the child and parent tables are the same.
A foreign key is a field in a table that matches another field of another table.
Another example is that, unless you disable the foreign key checks, you cannot drop a table that is referenced by a foreign key constraint.