|
Database Triggers
Database Triggers are one of the good features available in ORACLE. Database
triggers are written on any table. There are 12 types of Database Triggers they
are:
1. Before Insert
2. After Insert
3. Before Update
4. After Update
5. Before Delete
6. After Delete
7. Before Insert for each row
8. After Insert for each row
9. Before Update for each row
10. After Update for each row
11. Before Delete for each row
12. After Delete for each row
It will be get executed as soon as any DML operation take place on table. It
will not get executed if user issues truncate command. Like procedures and
functions no p-code (compile code) will not be available for database trigger in
database. Each time trigger get executed ORACLE will compile trigger and
generate p-code. Because of this some time performance of ORACLE will get
affected. In trigger we can use: NEW. <Column name> and : OLD.<Column name> to
get new and old value of table column. We can’t use: OLD in insert trigger. We
can’t user: NEW in delete trigger.
Syntax of creating Database Trigger is
CREATE OR REPLACE TRIGGER <Trigger Name >
After/Before Insert/Update/Delete on <Table Name>
Reference New as New Old as Old <for Each Row
Declare
Declare required Variables
Begin
Body
End.
|