I understand very well the idea behind triggers, how and when to use them.
I also see the practical use of a FOR EACH ROW
trigger.
But I lack to find a concrete example of when I would use a FOR STATEMENT
trigger. What could I do with it?
Can anyone give me an example of a real life use of that?
Best Answer
I cannot speak to all database platforms that support statement level triggers, but DB2 LUW also supports both row level triggers AND statement level triggers.
Referencing the documentation for DB2 LUW (highlighting mine) - Specifying what makes a trigger fire (triggering statement or event)
For example, keeping a count of number of employees can be done using FOR EACH ROW.
You can achieve the same affect with one update by using a granularity of FOR EACH STATEMENT.
Some examples of why you might want to use a statement level trigger over a row level trigger: