Is it good practice to update data in related tables through triggers?
-
Is it good practice to update data in the related (FOREIGN KEY-external key) tables, through the triggers?
There are two updates:
1♪through trigglers
2♪by adding a parameter - ON UPDATE CASCADE
What is the preferred option?
Note: Data will be added and updated only in the parent table. But we'll read these data from the daughter's table that's linked to the parent. And for us to get the relevant data from the bottom of the table, we have to, like, "synchronous" or almost synchronously update it from the parent table. Therefore, I am considering two options that have been described above.
-
The integrity of the tables can only be monitored through the external key. That is, ForeignKeyId will always indicate the record in the parent table. The only data you can update is this Id with the ON UPDATE CASCADE parameter.
Trigger gives you flexibility. For example, if cyclical disposal is possible, cascade disposal cannot be created in principle, and in any case only the trigger will save you.
The bottom of the triggers is that they are often invisible and difficult to understand, for example, why, when removed, there's a mistake in a table with which you seem to be not working at this point.