Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete on cascade in other direction

Is there a way to use the ON DELETE CASCADE option in the other direction? (DB2)

I have a (A one-to-many B) relation and delete one item from B and I want that the item A which is a foreign key from B also will be deleted.

Is that possible ?

like image 513
user3117357 Avatar asked Dec 07 '25 05:12

user3117357


1 Answers

Your request makes no sense.

You seem to want to delete A whenever a single B is deleted -- but deleting a would cause a cascade delete of all related Bs.

Also logically the definition for a default ONE to MANY is "A may have zero or more Bs".

In a physical design this must be the case. A customer record must exist before any orders can be placed against the customer so at some point you have to have a customer with no orders.

like image 115
James Anderson Avatar answered Dec 08 '25 19:12

James Anderson