Professional Documents
Culture Documents
(TAE 2)
Subject: DBMS
Guided by: Prof. Neha Purohit
-Submitted by: Varun Dalal (CSE -4-C-25)
What is a ‘TRIGGER’?
• A trigger is a function that is triggered automatically when a database
event like INSERT, UPDATE or DELETE occurs.
AFTER trigger will be fired after the triggering SQL statement is executed.
INSTEAD OF trigger will be fired when the user inserts data into a table
via a view.
{INSERT | UPDATE | DELETE}
• These are the event names. The trigger will be triggered when
the SQL statement contains any of these events.
ON table_name
• This statement specifies the table name on which the trigger is
being applied
{FOR EACH ROW| FOR EACH STATEMENT}
3
2. AFTER INSERT
1 4
2
5
6
3
3.AFTER UPDATE
4
1
3 6
Output
4.BEFORE UPDATE
1 3
2
5.BEFORE DELETE
1 3
4
2
5
6.AFTER DELETE
1 4
2
5
3
DISABLING TRIGGER
ALTER TABLE table_name
DISABLE TRIGGER trigger_name | ALL
For ex:
ALTER TABLE CR
DISABLE TRIGGER CR_TRIGG;
//This will disable the CR_TRIGG trigger until it is enable back.
ALTER TABLE CR
DISABLE TRIGGER ALL;
//This will disable all triggers associated with CR table until we enable it back.
//Please Note that disabling a trigger does not delete it!!!
ENABLE TRIGGER BACK
ALTER TRIGGER trigger_name ENABLE;
For ex:
ALTER TRIGGER CR_TRIGG ENABLE;
//This will enable the CR_TRIGG back
DROP TRIGGER
Syntax:
DROP trigger_name ON TABLE table_name;
For example:
DROP CR_TRIGG ON TABLE CR;
Thank you!!!