Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you check for updates across many tables in Oracle?

I have a trigger to check for a single column in a table, when there is an update (AFTER UPDATE) in that column my trigger is called and then I call a stored procedure from within my trigger in order to perform some business logic coded in Java.

So far, so good. Now things are getting more complicated, there is a new requirement that implies that the same logic (the logic executed by the trigger) should be also be performed if there are changes in columns that are in other 4 tables. I think it's not practical to have the same trigger in 5 different tables listening for different columns, and I'm not sure if I should consider creating a "view" for these columns and put a single trigger in that view (what is the cost to pay in terms of performance and/or resources?)

In your previous experience with Oracle, what have been your approach or solutions for this scenario?

like image 866
Abel Morelos Avatar asked Aug 27 '09 06:08

Abel Morelos


People also ask

How do I update multiple tables?

To UPDATE a table by joining multiple tables in SQL, let's create the two tables 'order' and 'order_detail. ' We can update the data of a table using conditions of other joined tables. It is possible to join two or more tables in an UPDATE query.

How can I update a column in multiple tables in Oracle?

If you need to update multiple columns simultaneously, use comma to separate each column after the SET keyword. update Categories_Test a set (a. Description, a. Picture) = (select b.

How do you update a column in multiple tables?

We can update multiple columns by specifying multiple columns after the SET command in the UPDATE statement. The UPDATE statement is always followed by the SET command, it specifies the column where the update is required.

Can I update multiple tables in single query?

For instance, updating 2 different tables together in a single query/statement. This involves the use of the BEGIN TRANSACTION clause and the COMMIT clause. The individual UPDATE clauses are written in between the former ones to execute both the updates simultaneously.


1 Answers

The only way you can use one trigger for multiple tables is to create view.

If I didn't want to create view, I'd create a script(or whatever, use the language you want) and a list of tables on which this trigger to be created (make the creating of triggers dynamic).. I see your point is to have best maintainability on this situation and I think creating a view is cleaner solution(and easy to maintain)than dynamic creating of a trigger for each table.

like image 192
Svetlozar Angelov Avatar answered Sep 18 '22 15:09

Svetlozar Angelov