I have a parent table say A and a child say B and B references A’s primary key
so most people will use on delete cascade to modify the tables when they delete from the parent A.
My question is: is there any example of a situation that I WILL NOT need ‘on delete cascade’?
When will it be not useful to use?
I have a parent table say A and a child say B and B
Share
I don’t like Marc B’s example, because products generally would not be “children” of a category. Products and Categories can overlap, with a many-to-many relationship.
I have ON DELETE SET NULL in situations where the data is still useful without the parent.
E.g.
Suppose you have a
translationstable that contains columnsid,translation_category,from_text,to_textThat table contains various text to text translations. The
translation_categoryis a foreign key that references a specific field where the translations would be primarily used. But you could also do queries that ignore that key to get a count of commonfrom_textandto_textvalues, since they may be repeated for differenttranslation_categoryvalues.That data is still perhaps useful even if you happen to delete one of the
translation_categoryparent records. So I would use ON DELETE SET NULL there.Of course, that same schema could be changed to put
translation_categoryinto a many-to-many linking table, but the same principles still apply.