DROP TRIGGER
In this page:
How to Drop a Trigger
DROP TRIGGER removes an active trigger from a table permanently — you need to reference it by its exact name, since triggers aren't tied to a specific column the way indexes can be.
Example: How to Drop a Trigger
DROP TRIGGER log_new_user;
Drop Trigger If Exists
Adding IF EXISTS to a DROP TRIGGER statement is standard defensive practice: it prevents the whole script from erroring out and stopping if the trigger was already removed by an earlier step.
Example: Drop Trigger If Exists
DROP TRIGGER IF EXISTS log_new_user;
Identifying Triggers Before Dropping
Before dropping a trigger, it's worth listing all triggers currently active in the database so you can confirm you have the correct name — trigger names aren't always as descriptive as the event they respond to.
Example: Identifying Triggers Before Dropping
SHOW TRIGGERS;
Dropping Table and Triggers
Dropping a table with DROP TABLE automatically removes every trigger attached to it as well, so you don't need to manually drop each trigger first before deleting the table itself.
Example: Dropping Table and Triggers
CREATE TABLE users (id INT);
CREATE TRIGGER log_new_user AFTER INSERT ON users FOR EACH ROW BEGIN END;
-- Dropping the table removes log_new_user too, no manual DROP TRIGGER needed
DROP TABLE users;
Cleaning Up Audit Tables
Cleaning up temporary logging or audit tables created while testing triggers is good practice, so leftover scaffolding doesn't accumulate in a production schema once the trigger work is finished.
Example: Cleaning Up Audit Tables
DROP TABLE IF EXISTS user_audit;
Chapter Quiz — Complete all 3 topics to unlock
0/3 topics done
Complete these topics first: