← Back to MySQL Course | Chapter 16: Triggers | Lesson 3 of 3

DROP TRIGGER

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

sql
DROP TRIGGER log_new_user;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

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

sql
DROP TRIGGER IF EXISTS log_new_user;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

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

sql
SHOW TRIGGERS;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

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

sql
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;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

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

sql
DROP TABLE IF EXISTS user_audit;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

🔒

Chapter Quiz — Complete all 3 topics to unlock

0/3 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.