Database trigger |
Database triggers are procedures that are stored in a Database and are executed or fired when a table is modified. They are very powerful tools that can be used to perform many tasks such as restricting access to specific data, perform logging, or auditing of data sets.
There are two classes of triggers, they are either row triggers or statement triggers . With row triggers you can define an action for every row of a table, while statement triggers only occur once and are not dependent on the shape of the data.
Each class can be of several types. There are BEFORE triggers and AFTER triggers which alters the time of execution of the trigger. There is also an INSTEAD OF trigger which is a conditional trigger that will fire instead of the triggering statement.
There are typically three triggering EVENTS that cause trigger to fire : *INSERT event (as a new record is being inserted into the database). *UPDATE event (as a record is being changed). *DELETE event (as a record is being deleted).
Databases that support triggers typically give programmers access to record variables by means of a syntax such as :OLD.cust_name or :NEW.cust_name. e.g. if a trigger is monitoring for changes to a salary field one could write a trigger. BEFORE UPDATE ON employee_table FOR ALL records IF :NEW.salary :OLD.salary THEN do something here END IF; END;
Oracle 9i allows you to create triggers on schemas and databases also.You can create a trigger for creating or altering or dropping a schema object.Triggers can also be created for logging in and logging out of databases.
Schema Level Triggers *Before Create *After Create *Before Alter *After Alter *Before Drop *After Drop *After Logon *Before Logoff
The major features and effects of database triggers are that they:
=Further reading=
*[http://www-rohan.sdsu.edu/doc/oracle/server803/A54643_01/ch15.htm Oracles Database Triggers]|
|