CodesJava

Easy learning with example program codes

ENABLE TRIGGER in Oracle

ORACLE ENABLE TRIGGER
As the name itself suggests, this type of trigger is used to ENABLE an already existing or newly created trigger for a table from the database. To serve this purpose ALTER TRIGGER statement is used.

Syntax:

ALTER TRIGGER trigger_name ENABLE;     

Parameters:
trigger_name: It is used to specify the name of the trigger to be created.
Example:

Students Table:

STUDENT_ID	STUDENT_NAME	STUDENT_AGE
1	        Joy	        20
2	        Smiley	        19
3	        Happy	        21
4	        James	        22
5	        Bond	        25

Create Trigger code:

CREATE OR REPLACE TRIGGER  "STUDENTS_T"   
AFTER INSERT or UPDATE or DELETE    
ON "STUDENTS"   
FOR EACH ROW
BEGIN  
WHEN the person performs insert/update/delete operations into the table.  
END;  
/  
ALTER TRIGGER  "STUDENTS_T" ENABLE  
/

Output:

TRIGGER NAME	TRIGGER TYPE	   TRIGGERING EVENT	             STATUS
STUDENTS_T	AFTER EACH ROW	   INSERT or UPDATE or DELETE	     ENABLED

Explanation:
The ‘students’ is an already existing table and a trigger is created with the name “STUDENTS_T”. AFTER the INSERT, UPDATE or DELETE statement is issued on the table “STUDENTS”, the Oracle database will fire the trigger, since it is in the ENABLED mode.

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status