Triggers
Triggers
TRIGGERS
• A group of SQL statements that are automatically executed by the database engine in
response to an insert, update or delete operation.
CREATING TRIGGERS
• Triggers are defined per time per event per table, and only one trigger per time per event per
table is allowed. As such, up to six triggers are supported per table (before and after each of
INSERT, UPDATE and DELETE)
• A single trigger cannot be associated with multiple events or multiple tables
• If you need a trigger to be executed for both INSERT and UPDATE operations, you'll need to
define two triggers
• Triggers cannot be updated or overwritten. To modify a trigger, it must be dropped and re-
created.
DROP TRIGGER nameOfTrigger;
INSERT TRIGGERS
– SQL statements;
• END;
• Substitute AFTER with BEFORE where necessary
DELETE TRIGGERS
– SQL statements;
• END;
• Substitute AFTER with BEFORE where necessary
UPDATE TRIGGERS
– SQL statements;
• END;
• Substitute AFTER with BEFORE where necessary
BANKING TASK
• Write triggers to automatically capture all activities (insert, update, delete) on each table