What are the advantages and disadvantages of Cascading removal and updates?

Perhaps this is a kind of naive question ... but I think that we should always have cascading deletions and updates. But I wanted to know if there are problems with this, and when should we not do this? I really can’t come up with a case right now when you don’t want to do a cascading deletion, but I'm sure there is one ... but what about updates, should they always be done?

So who can talk about the pros and cons of cascading deletions and updates? Thank.

+5
source share
4 answers

Pros:

  • When you delete a row from the parent table, all rows of the foreign key are deleted.
  • ,

  • , , PITA, , .
+8

, : , .

. g.: - , - .

, "" / , , ?

: , ORM ( ) , .

+5

:

  • - , , .

:

  • . / sloooooooooooooooooooow.
  • . , , , , , , , , .
  • , .
+1

Pro: it allows you to reduce the number of SQL statements needed to perform uninstall actions.

Con: you can delete data that may be of some importance to the audit at a later time. Therefore, it is important to keep it even if the parent line has been deleted. In this case, the foreign key should be NULL, for example.

-1
source

All Articles