?> Database Trigger Usage[Syntax]

Creating Triggers  «Prev 

How to use a trigger in Oracle

When creating a trigger, consider how the trigger affects the data in the table. For example, if you wish to change the value of one column of data when inserting a row, your trigger should fire before the insert and should fire once per row. A trigger that is used to record who performs updates on a table can fire either before or after the update and should fire once per transaction.
A trigger is a pl/sql block structure which is fired when a DML statements like Insert, Delete, Update is executed on a database table. A trigger is triggered automatically when an associated DML statement is executed.

The Syntax for creating a trigger is:
 CREATE [OR REPLACE ] TRIGGER trigger_name 
 {BEFORE | AFTER | INSTEAD OF } 
 {INSERT [OR] | UPDATE [OR] | DELETE} 
 [OF col_name] 
 ON table_name 
 [REFERENCING OLD AS o NEW AS n] 
 [FOR EACH ROW] 
 WHEN (condition)  
 BEGIN 
   --- sql statements  
 END;