3

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 ?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user3117357
  • 45
  • 1
  • 3

1 Answers1

1

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.

James Anderson
  • 27,109
  • 7
  • 50
  • 78
  • Which is the case when you do a normal cascade. i.e. you delete the customer and any referencing orders no longer have a customer, before they're deleted via the cascade. Also, it might be one-to-one and not one-to-many. – Ian Warburton Apr 25 '16 at 20:06