I was wondering if it is indirectly possible to have a trigger executed just before the transaction is about to commit? In this trigger, I will do consistency checks and rollback the transaction if required.
For example, I have three tables:
users (id, name)
groups (id, name)
user_in_group (user_id, group_id)
I would like to create a trigger which verifies that a user is always part of a group. No orphan users are allowed. Each time an insert into users occurs, this trigger will verify that a correspondering insert into user_in_group also occured. If not, the transaction will not commit.
This cannot be done using a simple row- or statement- based trigger, since the above scenario requires two separate statements.
The other way around, when a delete from user_in_group happens, can be easily done by a row-based trigger.