Types of Trigger1
Types of Trigger1
Types of Trigger1
Types of Triggers: Type of trigger firing, level at which a trigger is executed, and the types of events form
the basis classification of triggers into different categories. The broad classification of triggers is as shown
below.
I. On the Basis of Type of Events
1. Triggers on System events
2. Trigger on User events
II. On the Basis of the Level at which Triggers are Executed
3. Row Level Triggers
4. Statement Level Triggers
III. On the Basis of Type of Trigger/Firing (or) Triggering Transaction
5. BEFORE Triggers
6. AFTER Triggers.
7. INSTEAD OF
1. Triggers on System Events.
System events that can fire triggers are related to instance startup and shutdown and error messages.
STARTUP triggers fire when the database is opened by an instance,
SHUTDOWN triggers fire just before the server starts shutting down an instance.
SERVERERROR triggers fire when a specified error occurs, or when any error occurs if no error
number is specified.
The DBMS_AQ package is one example of using database triggers to perform certain actions. For example,
a database shutdown trigger is defined at the database level
CREATE TRIGGER register_shutdown ON DATABASE
SHUTDOWN
BEGIN
.........
DBMS_AQ.ENQUEUE(...);
.........
END;
2. Triggers on user events: User events that can fire triggers are related to
User logon and logoff
DDL statements (CREATE, ALTER, and DROP)
DML statements (INSERT, DELETE, and UPDATE)
This trigger tests time of the update against the CUSTOMER table and rejects any updates before 8AM or
after 6PM.
5. Before Triggers:
BEFORE triggers execute the trigger action before the triggering statement is executed.
Trigger Type Combinations: You can create 2 types of row and statement
triggers
BEFORE statement trigger.
Before executing the triggering statement, the trigger action is run.
BEFORE row trigger
Before modifying each row affected by the triggering statement and before checking appropriate
integrity constriants, the trigger action is run
6. AFTER Trigers:
AFTER triggers execute the trigger action after the triggering statement is executed.
Trigger type combinations: You can crate 2 types of row and statement triggers
AFTER statement trigger : After executing the triggering statement and applying any deferred
integrity constraints, the trigger action is run.
AFTER row trigger : After modifying each row affected by the triggering statement and possibly
applying appropriate integrity constraints, the trigger action is run for the current row provided the
trigger restriction was not violated.
SQL> CREATE OR REPLACE TRIGGER PASSENGER DEL AFT AFTER DELETE ON RESERV DET
FOR EACH ROW
BEGIN
DELETE FROMPASSENGER DET WHERE PASSENGER DET .PASSNO.. OLD.PASSNO:
END;
/
Trigger created.
7. INSTEAD-OF Triggers:
INSTEAD-OF triggers are used to tell Oracle what to do instead of performing the actions that executed the
trigger. It is applicable to both object views and standard relational database. This trigger can be used to
redirect table inserts into a different table or to update different tables that are the part of the view.