← Back to MySQL Course | Chapter 2: Databases & Tables | Lesson 5 of 7

DROP TABLE

DROP TABLE किसी wall से एक पूरा chart हटाने जैसा है, उस पर लिखी information की सारी rows और खुद chart सहित।
Syntax
sql
DROP TABLE [IF EXISTS] table_name;

एक Table Delete करना

DROP TABLE table का structure और इसकी हर row of data permanently हटा देता है — TRUNCATE के उलट, बाद में structure सहित कुछ भी table नहीं बचता। क्योंकि यह operation बिना backup के irreversible है, यह everyday SQL work के सबसे dangerous statements में से एक है।

उदाहरण: Deleting a Table

sql
DROP TABLE users;

Safe Table Deletion

IF EXISTS add करना table पहले से गई होने पर एक fatal error से बचाता है, जो unpredictable environments के against चलाई गई idempotent migration या cleanup scripts में ज़रूरी है। बिना IF EXISTS के, same cleanup script को लगातार दो बार चलाना दूसरे attempt पर एक error throw करेगा।

उदाहरण: Safe Table Deletion

sql
DROP TABLE IF EXISTS users;

कई Tables Delete करना

आप एक single DROP TABLE statement में commas से separated कई table names list करके उन सबको एक साथ हटा सकते हैं, जो अलग statements से तेज़ और कम error-prone दोनों है।

उदाहरण: Deleting Multiple Tables

sql
DROP TABLE IF EXISTS users, orders, logs;

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

Schema Contexts के साथ Delete करना

किसी table को उसके database name से prefix करना आपको पहले USE के through अपने session का active context बदले बिना किसी दूसरे database में एक table drop करने देता है। यह syntax, जैसे 'DROP TABLE other_db.table_name', एक साथ कई databases manage करने वाली admin scripts के लिए उपयोगी है।

उदाहरण: Deleting with Schema Contexts

sql
DROP TABLE other_db.users;

Table Deletion Verify करना

बाद में SHOW TABLES चलाना confirm करता है कि table actually गई या नहीं — यह मानने से पहले एक cheap, worthwhile check कि एक destructive cleanup script ने actually वह किया जो आपने intend किया था। यह production में एक migration या seed script के DROP statements के actually expected तरीके से चलने की उम्मीद से पहले भी एक अच्छी habit है।

उदाहरण: Verifying Table Deletion

sql
SHOW TABLES;

⚠️ 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. बिना backup के DROP TABLE users; चलाना, क्योंकि table और इसकी सारी rows गायब हो जाती हैं और rollback नहीं हो सकतीं।
  2. एक ऐसी table drop करना जिसे कोई दूसरी table एक foreign key से reference करती है, जो constraint हटाए जाने तक fail होता है।
  3. DROP TABLE इस्तेमाल करना जब सिर्फ rows जानी चाहिए थीं, जबकि TRUNCATE या DELETE table structure रखते।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 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.