Oracle Foreign keys only have cascade deletion and no Cascade update, but sometimes such functions may be required in the system, so the implementation process is recorded here.
Oracle Foreign keys only have cascade deletion and no Cascade update, but sometimes such functions may be required in the system, so the implementation process is recorded here.
Oracle Foreign keys only have cascade deletion and no Cascade update, but sometimes such functions may be required in the system, so the implementation process is recorded here.
There are two constraints in Oracle: latency constraint and non-latency constraint. The so-called non-Delay Constraint means that when a record is changed, it will immediately check the constraints and check whether the modification cannot be performed because it violates certain constraints, the latency constraint means that the constraints will not be viewed when the modifications are just made. The constraints will be checked only when the modifications are submitted. This feature is used for Oracle cascade updates.
1. First, set the foreign key as a latency constraint. The specific statement is as follows:
Add a foreign key to the TEST_2 table, reference it to TEST_1, and set it to cascading deletion and latency constraint (DEFERREABLE ). If you are using the Oracle SQL Developer tool, you can check whether the setting is successful in the constraints column.
2. Set the trigger
Set a trigger on the TEST_1 table. When the primary key of the table changes, the fields in TEST_2 are updated in cascade mode.
The cascade update of Foreign keys can be implemented in steps 1 and 2. The basic idea is that when the primary key of the master table is updated, the delay constraint is imposed and the check is not performed immediately. After the trigger is updated, the foreign key of the attached table is updated cascade, and then submitted, this will check the constraints. Because the foreign key has been cascade updated, there will be no problem here.