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

DROP DATABASE

DROP DATABASE पूरी filing cabinet को drawers और papers सहित एक bonfire में फेंकने जैसा है। इसे वापस पाने का कोई तरीका नहीं है।
Syntax
sql
DROP DATABASE [IF EXISTS] database_name;

एक Database Delete करना

DROP DATABASE database और इसके अंदर की हर table, row, और index को एक irreversible step में permanently delete कर देता है — कोई built-in undo नहीं है, इसलिए इस command को rm -rf जितनी ही caution चाहिए।

उदाहरण: Deleting a Database

sql
DROP DATABASE shop;

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

Safe Database Deletion

IF EXISTS add करना target database पहले से गई होने पर एक hard error से बचाता है, जो automated teardown scripts में मायने रखता है जो किसी unknown state वाले environment के against चल सकती हैं।

उदाहरण: Safe Database Deletion

sql
DROP DATABASE IF EXISTS shop;

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

Custom Schemas Delete करना

SCHEMA बस एक synonym है जो MySQL DATABASE के लिए accept करता है, इसलिए DROP SCHEMA और DROP DATABASE exactly वही करते हैं — यह जानना उपयोगी है क्योंकि दूसरे tools और documentation दोनों terms को interchangeably इस्तेमाल करते हैं।

उदाहरण: Deleting Custom Schemas

sql
DROP SCHEMA IF EXISTS shop;

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

Test Systems को Clean करना

एक database को drop और recreate करना एक test या staging environment को एक known-clean state में reset करने का एक common तरीका है, पिछले runs से accumulated किसी भी test data या schema drift को मिटाते हुए।

उदाहरण: Cleaning Up Test Systems

sql
DROP DATABASE IF EXISTS test_env;
CREATE DATABASE test_env;

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

Deletion Verify करना

drop करने के बाद, SHOW DATABASES चलाना confirm करता है कि नाम अब list में नहीं दिखता — यह मानने से पहले एक cheap sanity check कि एक automated cleanup script actually succeed हुई।

उदाहरण: Verifying Deletion

sql
SHOW DATABASES;

⚠️ 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. गलत server पर या बिना backup के DROP DATABASE shop; चलाना, जो इसमें मौजूद हर table permanently delete कर देता है।
  2. किसी script में IF EXISTS भूल जाना, ताकि database missing होने पर यह एक error के साथ रुक जाए।
  3. जिस database को आप इस समय इस्तेमाल कर रहे हैं उसे drop करने की कोशिश करना और फिर बिना USE के queries चलाना।
🔒

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.