|
|
|
Oracle Tips by Burleson |
Enforcing a Cascade Update
What do we need to enforce a cascade update?
One method is to utilize data dictionary tables and views to
backtrack foreign key relations and then apply updates along this
path. However, this may be a lengthy process and can be cause a
performance problem. A simpler method is to implement a table-based
cascade update. The table would contain the information that a
procedure would need to update all tables that are dependent upon a
main, or master, table. Therefore, the table would have to contain
the master table name, the dependent table(s), and, in case we can’t
duplicate the exact column name across all of the dependent tables,
the column to update. The table DDL script in Listing 4.3 meets
these requirements. If required, a fourth column indicating an
update order could be added, and the cursor in the UPDATE_TABLES
procedure (detailed later) would have to be altered to do an ordered
retrieve of the information. Listing 4.3 shows the required CREATE
TABLE command.
The table by itself would be of little use.
Since the data in the table is dynamic (i.e., multiple tables and
columns that would have to be addressed), we must enable our trigger
to be able to dynamically reassign these values. The easiest way to
do this is to create a set of procedures that utilize the DBMS_SQL
Oracle-provided package to dynamically reassign our update
variables. Source 4.1 shows the commented code for just such a
procedure set, which consists of two procedures: UPDATE_TABLES and
UPDATE_COLUMN.
See Code Depot
www.oracle-script.com |