Skip to content
Advertisement

How do I get results of SQL data change statement with triggers updates applied?

I have a requirement where I need to get the immediate result of an update statement. I saw that I can do that by using the SQL data-change-statement modifiers. However, I’m not being able to get the final result after applying all associated triggers. For example, let’s say I have the following query:

SELECT empno, salary FROM FINAL TABLE
    (UPDATE employee SET salary = salary * 1.10 WHERE job = 'CLERK')

And let’s suppose I have a trigger that does the following:

CREATE TRIGGER EXTRA_PAY_RISE AFTER UPDATE ON employee 
REFERENCING OLD AS oldrow  
NEW AS newrow 
FOR EACH ROW MODE DB2SQL 
WHEN (newrow.dept = 'sales')
UPDATE employee SET salary = salary * 1.01 WHERE name = newrow.name;

How can I get the result from the first select statement containing the updates applied by all of the associated triggers (if that’s possible)?

Advertisement

Answer

Use BEFORE UPDATE trigger and either NEW TABLE (in any case) or FINAL TABLE (if you don’t have AFTER UPDATE triggers).

If you can’t use BEFORE trigger to implement your update logic, then you can’t use a data-change-statement to achieve your goal.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement