I have two tables tabA and tabB, that are identical. I want to create a mechanism that for each time a new row is inserted into tabA the row shall also "automatically" be inserted into rowB. If rows are deleted in tabA, nothing shall happen in tabB.
I have used insert triggers for this but have had some problems. I have also got some comments that triggers should not be used for this.
So, what should I use? Materialized views demands that tabA and tabB are the same.
In a perfect world one would strive to isolate table changes to a single program unit in order to uniformly apply business logic requirements such as this without impact to existing code that is driving the inserts. That said, many times this is not the best solution in practice, due to scattered inserts throughout an application. In that case, while not optimal, an insert trigger could easily be seen as the most pragmatic solution.
You could write a stored procedure that accepts the column values as parameters, and then applies an INSERT to both tabA and tabB.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With