|
When you define a trigger, you can specify the number of times the trigger action is to be
executed once for every row affected by the triggering statement or once for the triggering
statement, no matter how many rows it affects.
Row Triggers
A row trigger is fired every time when the triggering statement affects the table. For
example, if an UPDATE statement updates several rows of a table, a row trigger is fired one time
for each row affected by the UPDATE statement. If a triggering statement affects no rows, a row
trigger is not executed at all.
Syntax for creating a row level trigger in Daffodil DB can be explained with the help of
following example:
create trigger after insert on test referencing new as refert
for each row when (testcol < 50) update test set testcol = 100
Statement Triggers
A statement trigger is fired once on behalf of the triggering statement, regardless
of the number of rows affected by the triggering statement. For example, even if a DELETE statement
deletes several rows from a table, a statement-level DELETE trigger is fired only once.
Statement triggers are useful if the code in the trigger action does not depend on the data
provided by the triggering statement or the rows affected. Following examples shows the syntax for
creating a statement level trigger in Daffodil DB
create trigger sample_trigger
before insert on teacher
for each statement
update teacher set salary=salary+20000
|