TechView with Kamlesh khaliya

Resources for OCP, Oracle Interviews(kamleshkhaliya@gmail.com)

Friday 8 July 2011

How to enable a trigger in oracle?

A Triggers is a stored program of database which executes (fire) in response of a particular event for example on addition of a row in a table. By default the triggers are enabled when first time we create them and later on we can disable the same.

The body of a trigger can be executed only if the trigger is in enabled state.

To enable a disabled trigger in oracle the syntax is :

ALTER TRIGGER trigger_name ENABLE;

For example if we have a trigger named refund_before_insert, we can enable it with following command:
ALTER TRIGGER   refund_before_insert ENABLE;

If you have defined more than one trigger on a table which are in disabled state then to enable all of those, you don't need to execute the above statement for each trigger. You can enable all the triggers created on a table by using the ALTER TABLE statement and the syntax is :

ALTER TABLE Table_Name
    ENABLE ALL TRIGGERS;

 For example on table Emp_Sal you have created 2 triggers one before and one after trigger. Which are presently in disabled state, so to enable both the triggers you can execute following  command:

ALTER TABLE Emp_Sal
    ENABLE ALL TRIGGERS;

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home