views:

515

answers:

2

Does the after Update trigger will kick off if there is a rollback?

Scenario: Lets say we update a table A and the trigger on table A kicks off and updates another table B with the details. If there is a rollback issued on table A due to some processing error, will the trigger cause the table B to rollback the change?

+6  A: 

Yes, it will.

Triggers work in scope of the DML statement's transaction (either started by you explicitly or by the DML statement itself implicitly)

When this transaction is rolled back, all changes made by the triggers are also rolled back.

However, if you put

PRAGMA autonomous_transaction

into the trigger definition, the trigger will start its own transaction which you should commit before the trigger completes.

Quassnoi
So the autonomous transaction is good if you want to log all ATTEMPTS to perform an update (even if they fail or are rolled back), but BAD if you only want the triggered action performed when the triggering updates succeeds and is committed. Beware!
Tony Andrews
You need explicit COMMIT for autonomous transactions. If you don't, it will fail with "ORA-06519: active autonomous transaction detected and rolled back"
jva
@jva: you're right, fixing.
Quassnoi
+1  A: 

Just a note - if you define AFTER UPDATE statement level trigger (without FOR EACH ROW clause) it will not fire if DML statement on the table fails and is rolled back.

jva