Order of Triggers in Merge Statements

The merge statement fires triggers in a specific order.

The merge statement fires triggers on the target table in this order:
  1. insert
  2. update
  3. delete

This means that even if the order number for an update statement is lower than the order number for an insert, the trigger for the insert statement fires first.

Multiple triggers for the same operation, however, are ordered. That is, all the triggers for insert are fired in order number first, followed by all the triggers, in order, for update, and so on.

In this example, the dbo creates these triggers on the GlobalSales table:
  • trigger1 for delete with order 1
  • trigger2 for delete with order 4
  • trigger3 for insert with order 1
  • trigger4 for insert with order 5
A merge statement merges data into GlobalSales. If the merge includes both insert and delete operations on GlobalSales, SAP ASE fires the triggers in this order after execution:
  • trigger3
  • trigger4
  • trigger1
  • trigger2