← Back to MySQL Course | Chapter 14: Views & Indexes | Lesson 4 of 5

DROP INDEX

DROP INDEX उन index pages को फाड़ने जैसा है जिनकी अब ज़रूरत नहीं, space बचाते हुए और book में changes को थोड़ा तेज़ बनाते हुए।
Syntax
sql
DROP INDEX index_name ON table_name;

ALTER TABLE table_name DROP INDEX index_name;

एक Index हटाना

DROP INDEX permanently एक ऐसा index हटाता है जिसकी अब ज़रूरत नहीं, यह इस्तेमाल कर रहा storage space free करते हुए और उस table पर हर insert या update पर MySQL जो overhead pay करता है उसे कम करते हुए।

उदाहरण: Removing an Index

sql
CREATE TABLE users (id INT, email TEXT);
CREATE INDEX idx_email ON users (email);
DROP INDEX idx_email ON users;

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

ALTER TABLE से Indexes Drop करना

Indexes को ALTER TABLE के through इसके DROP INDEX clause इस्तेमाल करके भी drop किया जा सकता है, जो handy है जब आप same statement में table पर पहले से दूसरे structural changes चला रहे हों।

उदाहरण: Dropping Indexes with ALTER TABLE

sql
CREATE TABLE users (id INT, email TEXT);
CREATE INDEX idx_email ON users (email);
ALTER TABLE users DROP INDEX idx_email;

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

हम Indexes क्यों Drop करते हैं

हर index की एक cost है: MySQL को indexed column के against हर insert, update, या delete पर इसे update करना पड़ता है, इसलिए queries actually कभी इस्तेमाल न करने वाले indexes हटाना write-heavy tables को noticeably तेज़ कर सकता है।

उदाहरण: Why We Drop Indexes

sql
CREATE TABLE logs (id INT, note TEXT);
CREATE INDEX idx_note ON logs (note);
-- Every INSERT now also updates idx_note -- drop it if queries never filter on note
DROP INDEX idx_note ON logs;

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

Primary Keys हटाना

किसी primary key के पीछे automatically बनाया गया index एक plain DROP INDEX से drop नहीं किया जा सकता — आप इसके बजाय इसे specifically ALTER TABLE ... DROP PRIMARY KEY से हटाते हैं।

उदाहरण: Removing Primary Keys

sql
CREATE TABLE users (id INT PRIMARY KEY, email TEXT);
ALTER TABLE users DROP PRIMARY KEY;

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

Drop करने से पहले Indexes देखना

किसी index को drop करने से पहले, किसी table पर currently defined indexes list करना उचित है ताकि आप guess करने और गलत को हटाने का risk लेने के बजाय exact नाम confirm कर सकें जिसे आप target कर रहे हैं।

उदाहरण: Viewing Indexes Before Dropping

sql
CREATE TABLE users (id INT, email TEXT);
CREATE INDEX idx_email ON users (email);
SHOW INDEX FROM users;

⚠️ 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. table का नाम बताए बिना एक index drop करना, क्योंकि MySQL को DROP INDEX idx_email ON users चाहिए।
  2. एक ऐसा index drop करना जिस पर एक foreign key depend करती है, जो तब तक fail होता है जब तक कोई दूसरा index exist न करे।
  3. DROP INDEX से एक primary key हटाने की कोशिश करना, जबकि इसे ALTER TABLE ... DROP PRIMARY KEY चाहिए।
🔒

Chapter Quiz — Complete all 5 topics to unlock

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