Drop Trigger
DROP TRIGGER statement drops a database trigger from the database.
Example
We will create table “demo_data”. Then create trigger “trg_drop_example” on demo_data table.
We will check the trigger status from “USER_TRIGGERS” table.
Then we will DROP the trigger and then check again the USER_TRIGGERS table. No records will be found from USER_TRIGGERS after DROP the Trigger.
Note:- USER_TRIGGERS table contains data related to all triggers and status of trigger.
Code
0 1 2 3 4 5 6 7 8 |
--Creating demo_data table. create table demo_data ( id number(5) primary key, project_name varchar2(10) ); |
Output
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
-- Creating TRIGGER CREATE OR REPLACE TRIGGER trg_drop_example BEFORE UPDATE OR DELETE OR INSERT ON demo_data FOR EACH ROW BEGIN -- business logic will be here to perform on any insert/update/delete dbms_output.put_line('trg_drop_example Trigger called.'); END; / |
Output
0 1 2 |
SELECT TRIGGER_NAME,STATUS FROM USER_TRIGGERS where upper(TRIGGER_NAME) = 'TRG_DROP_EXAMPLE'; |
TRIGGER_NAME | STATUS |
---|---|
TRG_DROP_EXAMPLE | ENABLED |
0 1 2 3 4 |
--DROP TRIGGER DROP TRIGGER hr.trg_drop_example; |
Output
In DROP TRIGGER statement, we specified schema name before trigger name. If you don’t specify schema name, then database will assume that the trigger is in your own schema.
Now again check the status of trigger.
0 1 2 |
SELECT TRIGGER_NAME,STATUS FROM USER_TRIGGERS where upper(TRIGGER_NAME) = 'TRG_DROP_EXAMPLE'; |