What is the importance of using ON DELETE CASCADE and ON UPDATE CASCADE in a table with foreign key(s)?

Asked

Viewed 71 times

-1

I wanted to know why it’s important to use ON DELETE CASCADE and ON UPDATE CASCADE in a table with foreign key(s), especially when there is Rigger in it(s)?

1 answer

0


The importance of using CASCADE is to ensure the referential integrity of the database, which ensures that a record (parent) that has a data referenced by another record (child), when updated (deleted or modified) reflect this in the record that has you as a reference, as well as allow the child not to have a corrupted data in his record (nonexistent reference).

Therefore, in ON DELETE CASCADE (if it is really necessary), all tuples in tables that have as FK the deleted tuple ID will be deleted, ensuring that there will be no tuples without FK. In ON UPDATE CASCADE, the table data when updated, if referenced in another table or in the same, will be updated in cascade.

In summary, it is to ensure the "REFERENTIAL INTEGRITY OF DATABASE".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.