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

DROP TRIGGER

DROP TRIGGER दीवार से motion sensor हटाने जैसा है। आपको exactly नाम बताना होगा कि किसे unplug करना है।
Syntax
sql
DROP TRIGGER [IF EXISTS] trigger_name;

एक Trigger कैसे Drop करें

DROP TRIGGER किसी table से permanently एक active trigger हटाता है — आपको इसे इसके exact नाम से reference करना ज़रूरी है, क्योंकि triggers indexes की तरह किसी specific column से tied नहीं होते।

उदाहरण: 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

एक DROP TRIGGER statement में IF EXISTS add करना standard defensive practice है: यह पूरी script को error होने और रुकने से रोकता है अगर trigger एक पहले के step से पहले ही हटाया जा चुका हो।

उदाहरण: 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.

Drop करने से पहले Triggers Identify करना

किसी trigger को drop करने से पहले, database में इस समय active सभी triggers list करना उचित है ताकि आप confirm कर सकें कि आपके पास सही नाम है — trigger names हमेशा उतने descriptive नहीं होते जितना वह event जिसका वे respond करते हैं।

उदाहरण: 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.

Table और Triggers Drop करना

DROP TABLE से एक table drop करना automatically इससे attached हर trigger भी हटा देता है, इसलिए table को खुद delete करने से पहले आपको manually हर trigger drop करने की ज़रूरत नहीं।

उदाहरण: 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.

Audit Tables Clean करना

Triggers test करते समय बनाई गई temporary logging या audit tables को साफ करना एक अच्छी practice है, ताकि trigger work खत्म होते ही leftover scaffolding किसी production schema में इकट्ठा न हो।

उदाहरण: 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.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. एक ऐसा trigger name drop करना जो exist नहीं करता, जो IF EXISTS इस्तेमाल न होने पर fail होता है।
  2. यह भूल जाना कि एक trigger एक database से belong करता है, इसलिए इसे सही schema से drop करना ज़रूरी है।
  3. एक trigger drop करना और यह भूल जाना कि इसने जो audit या validation handle किया वह अब नहीं होता।
चैप्टर सारांश
  • एक trigger automatically चलता है जब एक table event होता है।
  • BEFORE और AFTER triggers एक change से पहले या बाद चलते हैं।
  • DROP TRIGGER एक ऐसा trigger हटाता है जिसकी अब ज़रूरत नहीं।
🔒

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.