Triggers

Triggers are procedures that are stored in the database that gets executed implictly on operations like INSERT, UPDATE and DELETE. Triggers can be DML triggers, INSTEAD OF triggers and Database and schema triggers. The events can take place BEFORE, AFTER and INSTEAD OF the INSERT, UPDATE and DELETE.

Events:
BEFORE triggers: Executes the specified events before writting the data onto the disk.
AFTER trigger:  Executes the specified events after writting the data onto the disk.
INSTEAD OF triggers: Executes the specified events instead of the original operation.

Syntax:

CREATE [OR REPLACE] TRIGGER <trigger_name>
BEFORE INSERT ON <table_name>
FOR EACH ROW
BEGIN
<pl/sql statement>
END;


Here:
<trigger_name> is the trigger name,
BEFORE is the keyword as discussed earlier and can be interchenged with AFTER and INSTEAD OF according to requirement,
INSERT is the event and can be replaced with DELTE and UPDATE ,
<table_name> is the table name on which trigger is defined,
FOR EACH ROW is an optional keyword that is used when trigger operation is required for each row in the table,
<pl/sql statement> is the pl/sql queries required as trigger operation 









No comments:

Post a Comment