Free tutorials & notes in Hindi & English · Clean code examples · Mobile friendly learning
Free tutorials in Hindi & English Daily computer, mobile and IT guides Beginner friendly learning
Blog · MySQL / SQL · 04 Jul 2026 · Hindi + English

SQL में DELETE, TRUNCATE और DROP में अंतर

DELETE चुनी हुई rows मिटाता है (undo हो सकता है), TRUNCATE पूरी table तेज़ी से खाली करता है, DROP table को structure समेत हटा देता है. Notebook analogy + पूरी table.

The notebook analogy

Imagine your attendance register (the table). DELETE = erasing specific entries with a pencil eraser — you choose which lines to remove, and if you change your mind quickly (ROLLBACK), you can restore them. TRUNCATE = tearing out ALL pages at once — fast, everything gone, register itself still exists, ready for fresh entries. DROP = throwing the whole register in the dustbin — pages, cover, everything. The register no longer exists at all.

See all three on one table

-- Our table
SELECT * FROM students;
+---------+--------+-------+
| roll_no | name   | class |
|     101 | Aman   | 10    |
|     102 | Priya  | 10    |
|     103 | Rahul  | 9     |
+---------+--------+-------+

-- 1. DELETE: remove chosen rows (WHERE decides which)
DELETE FROM students WHERE class = '9';
-- Result: Rahul gone, Aman & Priya remain. Table structure intact.

-- 2. TRUNCATE: empty the whole table instantly (no WHERE possible)
TRUNCATE TABLE students;
-- Result: 0 rows. Table structure intact. AUTO_INCREMENT resets to 1.

-- 3. DROP: destroy the table itself
DROP TABLE students;
-- Result: table gone. SELECT now gives: Table 'students' doesn't exist

The rollback difference — proof

START TRANSACTION;
DELETE FROM students WHERE roll_no = 101;
ROLLBACK;                     -- Aman is BACK. DELETE is a DML command,
SELECT * FROM students;       -- logged row by row, so it can be undone.

START TRANSACTION;
TRUNCATE TABLE students;
ROLLBACK;                     -- rows do NOT come back in MySQL!
                              -- TRUNCATE is DDL - it auto-commits.
This is the interview-deciding point: DELETE is DML (row-by-row, logged, rollback possible). TRUNCATE and DROP are DDL (they auto-commit in MySQL — once done, done). Never test TRUNCATE on production data thinking you can undo it.

Full comparison table

PointDELETETRUNCATEDROP
RemovesChosen rows (or all)All rows onlyEntire table + structure
WHERE clause✅ Yes❌ No❌ No
Command typeDMLDDLDDL
Rollback (MySQL)✅ Inside transaction❌ Auto-commits❌ Auto-commits
Speed on big tablesSlow (row by row)Very fastFast
AUTO_INCREMENTContinues (104, 105...)Resets to 1— (table gone)
Triggers fire✅ Yes❌ No❌ No

Which one when? (real situations)

  • DELETE — "remove students who left in 2025" → selective, safe, needs WHERE.
  • TRUNCATE — "clear last year's attendance table before the new session" → keep structure, wipe data fast, restart IDs.
  • DROP — "this old backup table is not needed anymore" → remove it completely.
  • Interview line: "DELETE removes rows selectively and can roll back; TRUNCATE empties the table fast and resets identity; DROP removes the table itself."

Register वाली analogy

अपना attendance register (table) सोचिए. DELETE = eraser से चुनी हुई entries मिटाना — आप चुनते हैं कौन-सी lines हटानी हैं, और जल्दी मन बदल जाए (ROLLBACK) तो वापस भी आ जाती हैं. TRUNCATE = सारे pages एक साथ फाड़ देना — तेज़, सब गया, register खुद अभी भी है, नई entries के लिए तैयार. DROP = पूरा register कूड़ेदान में — pages, cover, सब. Register का अस्तित्व ही खत्म.

तीनों को एक table पर देखिए

-- हमारी table
SELECT * FROM students;
+---------+--------+-------+
| roll_no | name   | class |
|     101 | Aman   | 10    |
|     102 | Priya  | 10    |
|     103 | Rahul  | 9     |
+---------+--------+-------+

-- 1. DELETE: चुनी हुई rows हटाओ (WHERE तय करता है कौन-सी)
DELETE FROM students WHERE class = '9';
-- Result: Rahul गया, Aman और Priya बचे. Table structure intact.

-- 2. TRUNCATE: पूरी table तुरंत खाली (WHERE possible नहीं)
TRUNCATE TABLE students;
-- Result: 0 rows. Structure intact. AUTO_INCREMENT 1 से reset.

-- 3. DROP: table को ही खत्म करो
DROP TABLE students;
-- Result: table गई. अब SELECT देगा: Table 'students' doesn't exist

Rollback वाला फर्क — proof

START TRANSACTION;
DELETE FROM students WHERE roll_no = 101;
ROLLBACK;                     -- Aman WAPAS aa gaya. DELETE DML command है,
SELECT * FROM students;       -- row by row logged, इसलिए undo हो सकता है.

START TRANSACTION;
TRUNCATE TABLE students;
ROLLBACK;                     -- MySQL में rows वापस NAHI आतीं!
                              -- TRUNCATE DDL है - auto-commit हो जाता है.
यही point interview तय करता है: DELETE DML है (row-by-row, logged, rollback possible). TRUNCATE और DROP DDL हैं (MySQL में auto-commit — एक बार हुआ तो हुआ). Production data पर TRUNCATE यह सोचकर कभी न चलाएं कि undo कर लेंगे.

पूरी comparison table

PointDELETETRUNCATEDROP
हटाता हैचुनी rows (या सब)सिर्फ सारी rowsपूरी table + structure
WHERE clause✅ हां❌ नहीं❌ नहीं
Command typeDMLDDLDDL
Rollback (MySQL)✅ Transaction में❌ Auto-commit❌ Auto-commit
बड़ी tables पर speedधीमा (row by row)बहुत तेज़तेज़
AUTO_INCREMENTआगे चलता है (104, 105...)1 से reset— (table ही गई)
Triggers चलते हैं✅ हां❌ नहीं❌ नहीं

कब कौन-सा? (असली situations)

  • DELETE — "2025 में निकले students हटाओ" → selective, safe, WHERE चाहिए.
  • TRUNCATE — "नए session से पहले पिछले साल की attendance table साफ करो" → structure रखो, data तेज़ी से मिटाओ, IDs restart.
  • DROP — "यह पुरानी backup table अब नहीं चाहिए" → पूरी तरह हटाओ.
  • Interview line: "DELETE selectively rows हटाता है और rollback हो सकता है; TRUNCATE table तेज़ी से खाली करके identity reset करता है; DROP table को ही हटा देता है."

Frequently Asked Questions

DELETE, TRUNCATE और DROP में main अंतर क्या है?

DELETE WHERE से चुनी rows हटाता है और rollback हो सकता है; TRUNCATE structure रखते हुए सारी rows तेज़ी से हटाकर AUTO_INCREMENT reset करता है; DROP table को structure समेत हटा देता है.

क्या MySQL में TRUNCATE rollback हो सकता है?

नहीं. TRUNCATE DDL command है जो MySQL में auto-commit हो जाता है, इसलिए चलने के बाद rows ROLLBACK से वापस नहीं आतीं — DELETE के उलट जो DML है.

TRUNCATE DELETE से तेज़ क्यों है?

DELETE rows को एक-एक करके हटाता और log करता है, triggers भी चलाता है; TRUNCATE बिना row-level logging के data pages एक operation में छोड़ देता है.