Tutorials
Oracle 9i
Tutorial 14: Oracle 9i : Database Triggers
Tutorial 14: Oracle 9i : Database Triggers - Page 2Database Triggers
A database triggers is stored PL/SQL program unit associated with a specific database table or view. The code in the trigger defines the action the database needs to perform whenever some database manipulation (INSERT, UPDATE, DELETE) takes place.
Sponsored Links
Unlike the stored procedure and functions, which have to be called explicitly, the database triggers are fires (executed) or called implicitly whenever the table is affected by any of the above said DML operations.
Till oracle 7.0 only 12 triggers could be associated with a given table, but in higher versions of Oracle there is no such limitation. A database trigger fires with the privileges of owner not that of user
A database trigger has three parts
A triggering event can be an insert, update, or delete statement or a instance shutdown or startup etc. The trigger fires automatically when any of these events occur A trigger constraint specifies a Boolean expression that must be true for the trigger to fire. This condition is specified using the WHEN clause. The trigger action is a procedure that contains the code to be executed when the trigger fires.
Types of Triggers
The following are the different types of triggers.
Row triggers and statement triggers
A Row trigger fires once for each row affected. It uses FOR EACH ROW clause. They are useful if trigger action depends on number of rows affected.
Statement Trigger fires once, irrespective of number of rows affected in the table. Statement triggers are useful when triggers action does not depend on
Before and afterTriggers
While defining the trigger we can specify whether to perform the trigger action (i.e. execute trigger body) before or after the triggering statement. BEFORE and AFTER triggers fired by DML statements can only be defined on tables.
BEFORE triggers The trigger action here is run before the trigger statement.
AFTER triggers The trigger action here is run after the trigger statement.
INSTEAD of Triggers provide a way of modifying views that can not be modified directly using DML statements.
LOGON triggers fires after successful logon by the user and LOGOFF trigger fires at the start of user logoff.
Points to ponder
Triggers on DDL statements
DDL trigger are of the following types
BEFORE CREATE OR AFTER CREATE trigger is fired when a schema object is created.
BEFORE OR AFTER ALTER trigger is fired when a schema object is altered.
BEFORE OR AFTER DROP trigger is fired when a schema object is dropped.
A trigger can be enabled means can be made to run or it can disabled means it cannot run. A trigger is automatically enabled when it is created. We need re-enable trigger for using it if it is disabled. To enable or disable a trigger using ALTER TRIGGER command, you must be owner of the trigger or should have ALTER ANY TRIGGER privilege. To create a trigger you must have CREATE TRIGGER privilege, which is given to as part of RESOURCE privilege at the time of user creation.
Following figures give more understanding about triggers



Sponsored Links

Next Page: Tutorial 14: Oracle 9i : Database Triggers - Page 2
|
Yes. This is very good site to beginers. Thanx a lot |
|
It is really good place for a beginner to learn. This article would be very fruitful, if you could give a strategy to avoid the mutating issue. Thanks for a wonderful basics. |
| Good and sufficient content |
|
Hi, Its a good place to begin with triggers. It provides solid funda. Please add the advanced info on triggers. Thanks Sami |
| Nice, short and excellent description of triggers. Good for beginners. Writtern in easy and lucid language and good illustrations too. |
| Nice description and good illustrations. Excellent for beginners. |
| I find it very useful for beginners. THX |
| hi dis is the good way of learning course |
| hi trigger concepts r very good also easy and simple |
|
It is really helpfull in refreshing the topic Thanks |
| This Document is rally good. |
| I was looking for some 1 minute intro to Triggers.....and I got it here the way I wanted. |
|
hi. this document is really good and excellent for beginners..... |
| Excellent Information for starters... Really easy to Understand |
|
very nice, but need to add more examples.. |
|
These is very Nice, but i need some more Examples. |
| Really its too good...Simple but descriptive |
| hey this is good one for getting the conecpt as a beginner level |
| Very easy to Understand instead of reading a chapeter in book |
|
Excellent Information for starters... Really easy to Understand |
| It's Really Good Site for Begginer's to learn.... |
| The info present above is very easy to understand .... thanks..... |
| This site is really good for understand.........thanks....... |
| Its good but you should give more examples in detailed manner |
| how many triggers we can make once please tell me somebody |
|
Hi Amit, Below are the trigger types, 1) Statement Level 2) System Level 3) Instead of Trigger 4) Row level Trigger For row and statement level we will create triggers as, Before and After statement and Row level Regards, Mahendra |
|
We can create any no. of trigger but the combination is 12 only. EX. INSERT/UPDATE/DELETE ROW/STATEMENT AFTER/BEFORE |
|
Can you have multiple conditions in the WHEN statement? WHEN (x=x && y=y) |
| How to create a trigger for a column in particular table which accepts only capital letters? |
| How to create trigger for a row which when deleted it's any one field (e.g. emp_no ) which is primary key, get inserted into another table ? |
| What is differend trigger and function? |
|
when we need to declare variables in DECLARE section ? kindly explain in details? mahesha..... |
|
what is the trigger & cursor? |
|
whats the use of the cusore? what is the use of procedure? |
| why do we use CREATE "[OR REPLACE]" , In the declaration of cursors, triggers ? |
| How are ways to create trigger about 'CREATE, UPDATE and DELETE' a DATABASE? May I get code of them? For example, I want to create a database to manage STUDENTS. How to code that? |
| Can you provide about explanation for trigger programs either insertion or deletion |