DROP vs TRUNCATE vs DELETE in SQL Notes in Hindi & English : SQL में DROP, TRUNCATE और DELETE के मध्य महत्वपूर्ण तकनीकी अंतर और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम DROP vs TRUNCATE vs DELETE in SQL (SQL में DROP, TRUNCATE और DELETE के मध्य महत्वपूर्ण तकनीकी अंतर) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: DROP, TRUNCATE, and DELETE remove data at distinct architectural layers: DELETE (DML) selectively removes logged rows using an optional WHERE clause, TRUNCATE (DDL) deallocates all table data pages while preserving the schema, and DROP (DDL) permanently eradicates both data and table metadata. They differ fundamentally in rollback safety, transaction logging volume, trigger execution, identity resets, and High Water Mark reclamation.

अध्याय सार: SQL में DROP, TRUNCATE और DELETE तीन भिन्न स्तरों पर डेटा हटाते हैं: DELETE (DML) वैकल्पिक WHERE शर्त से चुनिंदा पंक्तियाँ हटाता है, TRUNCATE (DDL) स्कीमा सुरक्षित रखते हुए सभी डेटा पेज खाली करता है, और DROP (DDL) डेटा सहित पूरी टेबल संरचना समाप्त कर देता है। इनके बीच रोलबैक, लॉगिंग, ट्रिगर, आइडेंटिटी रीसेट तथा स्पेस मुक्ति में बड़ा अंतर होता है।

DROP vs TRUNCATE vs DELETE in SQL: Detailed Notes & Architecture (SQL में DROP, TRUNCATE और DELETE के मध्य महत्वपूर्ण तकनीकी अंतर)

1. Architectural Scope and Sublanguage Classification (DML vs DDL) (आर्किटेक्चरल स्तर और उप-भाषा वर्गीकरण (DML बनाम DDL))

[EN] DELETE is a Data Manipulation Language (DML) command operating at the row (tuple) level and accepts an optional WHERE condition to filter target rows; omitting WHERE deletes every row sequentially. TRUNCATE is a Data Definition Language (DDL) command operating at the page/extent storage level—it empties the entire table and CANNOT take a WHERE clause. DROP is also a DDL command operating at the schema object level, removing all rows alongside indexes, constraints, triggers, grants, and the catalog entry.

[HI] DELETE एक DML कमांड है जो पंक्ति (Row) स्तर पर कार्य करता है और वैकल्पिक WHERE शर्त से चुनिंदा डेटा हटाता है (WHERE न देने पर सारी पंक्तियाँ हटती हैं)। TRUNCATE एक DDL कमांड है जो स्टोरेज पेज स्तर पर पूरी टेबल खाली करता है और इसमें WHERE शर्त नहीं लग सकती। DROP भी एक DDL कमांड है जो ऑब्जेक्ट स्तर पर डेटा सहित इंडेक्स, ट्रिगर, कंस्ट्रेंट्स और टेबल परिभाषा सब नष्ट कर देता है।

2. Logging Overhead, Execution Speed, and Rollback Semantics (ट्रांज़ैक्शन लॉगिंग, गति और रोलबैक क्षमता)

[EN] DELETE generates full row-level Undo and Redo log entries for every deleted tuple, making it slow on multi-million-row tables while guaranteeing full ROLLBACK capability prior to COMMIT. TRUNCATE writes minimal metadata logs (recording only page/extent deallocations rather than individual tuples), executing almost instantaneously. In MySQL and Oracle, TRUNCATE and DROP issue an implicit COMMIT and CANNOT be rolled back; however, PostgreSQL and SQL Server log DDL page deallocations so TRUNCATE/DROP inside BEGIN ... ROLLBACK can actually be undone there.

[HI] DELETE हर हटाई गई पंक्ति का अलग Undo/Redo लॉग बनाता है, जिससे बड़ी टेबल पर यह धीमा होता है किंतु COMMIT से पहले पूर्णतः ROLLBACK हो सकता है। TRUNCATE केवल पेज डी-एलोकेशन का न्यूनतम लॉग लिखता है जिससे यह लाखों पंक्तियाँ सेकंडों में हटा देता है। MySQL व Oracle में TRUNCATE व DROP स्वतः कमिट होकर रोलबैक नहीं होते, जबकि PostgreSQL व SQL Server में ट्रांज़ैक्शन ब्लॉक के भीतर ये रोलबैक हो सकते हैं।

3. Trigger Firing, Identity/Auto-Increment Counters, and High Water Mark (ट्रिगर फायरिंग, आइडेंटिटी रीसेट और हाई वाटर मार्क (HWM))

[EN] Three classic exam distinctions separate DELETE and TRUNCATE: (1) Triggers—DELETE fires row-level BEFORE/AFTER DELETE triggers for each row, whereas TRUNCATE bypasses row-level ON DELETE triggers completely. (2) Sequence Counters—DELETE preserves the current AUTO_INCREMENT/IDENTITY counter (next insert after deleting 1..100 gets 101), whereas TRUNCATE resets the counter back to its seed (next insert gets 1). (3) Storage Space—DELETE leaves allocated extents and the High Water Mark (HWM) intact, whereas TRUNCATE resets the HWM and reclaims freed space immediately.

[HI] परीक्षा में तीन प्रमुख अंतर सर्वाधिक पूछे जाते हैं: (1) Triggers—DELETE प्रत्येक पंक्ति पर ON DELETE ट्रिगर चलाता है, जबकि TRUNCATE ट्रिगर फायर नहीं करता। (2) Auto-Increment—DELETE करने के बाद अगली नई पंक्ति को पिछली संख्या से आगे का ID मिलता है, जबकि TRUNCATE काउंटर को पुनः 1 (Seed) पर रीसेट कर देता है। (3) High Water Mark—DELETE खाली किए ब्लॉक वापस OS/टेबलस्पेस को नहीं लौटाता (HWM वही रहता है), जबकि TRUNCATE HWM को घटाकर तुरंत स्पेस मुक्त कर देता है।

4. Foreign Key Constraints and Privilege Requirements (फॉरेन की प्रतिबंध और आवश्यक अधिकार (Privileges))

[EN] DELETE integrates directly with referential integrity actions: deleting a parent row triggers ON DELETE CASCADE, SET NULL, or checks child rows individually. Conversely, most SQL engines forbid TRUNCATE TABLE on any parent table referenced by an active FOREIGN KEY—even when the child table currently contains zero rows—because TRUNCATE does not scan rows or fire cascading deletes. Security-wise, DELETE requires only DML DELETE privilege, while TRUNCATE and DROP typically require higher table-owner or ALTER/DROP DDL privileges.

[HI] DELETE फॉरेन की नियमों के साथ कार्य करते हुए पंक्ति-दर-पंक्ति ON DELETE CASCADE या SET NULL लागू कर सकता है। इसके विपरीत, यदि किसी टेबल पर सक्रिय FOREIGN KEY संदर्भ बना है, तो चाइल्ड टेबल खाली होने पर भी अधिकांश इंजन पेरेंट पर TRUNCATE नहीं चलने देते क्योंकि TRUNCATE पंक्तियाँ स्कैन नहीं करता। अधिकारों के स्तर पर DELETE के लिए केवल DML DELETE अनुमति चाहिए, जबकि TRUNCATE व DROP के लिए उच्च DDL (ALTER/DROP) अधिकार जरूरी होते हैं।

Syntax, Formula & Technical Example (DROP vs TRUNCATE vs DELETE in SQL)

-- Comparing DELETE, TRUNCATE, and DROP on Orders(OrderID AUTO_INCREMENT):
-- Case A: Selective DML removal (logged, fires triggers, keeps next OrderID)
DELETE FROM Orders WHERE Amount < 100;
ROLLBACK;                       -- Safely restores rows

-- Case B: Fast DDL wipe (skips triggers, resets OrderID to 1, frees pages)
TRUNCATE TABLE TempOrders;

-- Case C: Complete DDL destruction (removes table schema from catalog)
DROP TABLE TempOrders;

DROP vs TRUNCATE vs DELETE in SQL Quick Reference & Comparison Table

SQL CommandSublanguage & Row FilteringTriggers, Auto-Increment & Space Effect
DELETEDML; supports optional WHERE clause for selective removalLogs every row, fires ON DELETE triggers, keeps AUTO_INCREMENT and HWM
TRUNCATEDDL; removes ALL rows without supporting WHEREMinimal page log, skips triggers, resets AUTO_INCREMENT and HWM
DROPDDL; deletes entire table schema, indexes, and dataRemoves object from catalog; destroys triggers, grants, and counters
Empty-Child FK RuleParent table referenced by active child FOREIGN KEYDELETE works row-wise (or cascades); TRUNCATE/DROP fail without CASCADE

DROP vs TRUNCATE vs DELETE in SQL Top 20 Bilingual MCQs with Answers

Q1. Which of the three commands—DROP, TRUNCATE, and DELETE—supports a WHERE clause to remove only specific rows?

(DROP, TRUNCATE और DELETE में से कौन सा कमांड केवल चुनिंदा पंक्तियों को हटाने हेतु WHERE क्लॉज का समर्थन करता है?)

(A) TRUNCATE and DELETE

(B) DROP and DELETE

(C) DELETE only

(D) All three support WHERE

Correct Answer: (C)

[EN] DELETE is row-level DML supporting WHERE; TRUNCATE and DROP are DDL commands operating on the entire table.

[HI] केवल DELETE (DML) में WHERE शर्त लगाकर विशिष्ट पंक्तियाँ हटाई जा सकती हैं; TRUNCATE व DROP पूरी टेबल पर चलते हैं।

Q2. Suppose table Users has an AUTO_INCREMENT primary key and currently holds IDs 1 through 50. After deleting all rows, a new user is inserted and receives ID = 1. Which command was used?

(Users टेबल में AUTO_INCREMENT ID 1 से 50 तक हैं। सारा डेटा हटाने के बाद नई पंक्ति डालने पर उसे ID = 1 मिला। कौन सा कमांड चलाया गया था?)

(A) UPDATE Users SET ID = NULL;

(B) DELETE FROM Users;

(C) TRUNCATE TABLE Users;

(D) DELETE * FROM Users WHERE ID > 0;

Correct Answer: (C)

[EN] TRUNCATE resets the AUTO_INCREMENT / IDENTITY seed back to 1 (while DELETE retains 51 as the next generated ID).

[HI] TRUNCATE कमांड AUTO_INCREMENT काउंटर को प्रारंभिक मान 1 पर रीसेट कर देता है, जबकि DELETE में अगली ID 51 मिलती।

Q3. Why is TRUNCATE TABLE dramatically faster than DELETE FROM TableName (without WHERE) on a 50-million-row table?

(5 करोड़ पंक्तियों वाली टेबल को पूरा खाली करने में बिना WHERE वाले DELETE की तुलना में TRUNCATE TABLE अत्यधिक तेज क्यों होता है?)

(A) DELETE automatically rebuilds every table index from scratch

(B) TRUNCATE deallocates entire data pages with minimal logging, whereas DELETE scans and logs every single row

(C) TRUNCATE deletes only the first 100 rows and hides the rest

(D) TRUNCATE runs in client browser RAM without touching the disk

Correct Answer: (B)

[EN] Row-by-row undo/redo logging, index entry updates, and trigger checks make un-filtered DELETE vastly slower than page deallocation in TRUNCATE.

[HI] DELETE प्रत्येक पंक्ति को पढ़कर Undo लॉग लिखता और इंडेक्स अपडेट करता है, जबकि TRUNCATE एक झटके में पूरे डेटा पेज मुक्त कर देता है।

Q4. Which statement accurately describes ON DELETE trigger behavior across DELETE, TRUNCATE, and DROP?

(DELETE, TRUNCATE और DROP में ON DELETE ट्रिगर चलने के विषय में कौन सा कथन सटीक है?)

(A) Only DROP fires ON DELETE triggers before removing schema

(B) TRUNCATE fires triggers twice per page

(C) Both DELETE and TRUNCATE fire ON DELETE triggers identically

(D) DELETE fires row-level ON DELETE triggers; TRUNCATE and DROP do NOT fire ON DELETE triggers

Correct Answer: (D)

[EN] Because TRUNCATE skips row-by-row scanning, no row-level ON DELETE triggers execute; DROP destroys triggers along with the table.

[HI] केवल DELETE प्रत्येक पंक्ति के लिए ON DELETE ट्रिगर चलाता है; TRUNCATE ट्रिगर नहीं चलाता और DROP टेबल सहित ट्रिगर ही मिटा देता है।

Q5. In Oracle databases, what happens to the table's High Water Mark (HWM) and freed extents after DELETE vs TRUNCATE?

(Oracle डेटाबेस में DELETE बनाम TRUNCATE के बाद टेबल के High Water Mark (HWM) और स्पेस पर क्या प्रभाव पड़ता है?)

(A) Both reset the HWM identically

(B) DELETE shrinks the HWM to zero while TRUNCATE keeps all blocks locked

(C) DELETE leaves the High Water Mark unchanged (holding allocated blocks), whereas TRUNCATE resets the HWM and reclaims extents

(D) Neither affects storage blocks or HWM

Correct Answer: (C)

[EN] After a huge DELETE, full table scans still walk up to the unchanged HWM; TRUNCATE resets the HWM downward and frees space immediately.

[HI] DELETE से HWM नीचे नहीं आता जिससे स्कैन में खाली ब्लॉक भी पढ़े जाते हैं, जबकि TRUNCATE HWM को रीसेट कर स्पेस तुरंत मुक्त कर देता है।

Q6. Table Child(Cid, Pid) has a FOREIGN KEY (Pid) REFERENCES Parent(Pid) ON DELETE CASCADE, and Child currently has 0 rows. What happens when you run TRUNCATE TABLE Parent?

(Child टेबल में Parent पर ON DELETE CASCADE फॉरेन की लगी है (भले ही Child अभी खाली हो)। TRUNCATE TABLE Parent चलाने पर क्या होगा?)

(A) Parent truncates cleanly and cascades to Child

(B) Most RDBMS engines reject TRUNCATE TABLE Parent with a Foreign Key reference error

(C) The Foreign Key converts to a PRIMARY KEY automatically

(D) Only Child gets truncated

Correct Answer: (B)

[EN] Because TRUNCATE cannot inspect rows or invoke cascading row deletes, engines forbid truncating any table referenced by an active FK unless disabled or using CASCADE in PostgreSQL.

[HI] TRUNCATE पंक्ति-दर-पंक्ति CASCADE नहीं चला सकता, इसलिए सक्रिय फॉरेन की होने पर Child खाली होने के बावजूद TRUNCATE अस्वीकृत हो जाता है।

Q7. Which two commands leave the table's columns, constraints, and structure intact after removing all rows?

(सारी पंक्तियाँ हटाने के बाद भी कौन से दो कमांड टेबल की संरचना, कॉलम्स और कंस्ट्रेंट्स को सुरक्षित रखते हैं?)

(A) DROP and DELETE

(B) DELETE and TRUNCATE

(C) DROP and TRUNCATE

(D) DROP only

Correct Answer: (B)

[EN] Both DELETE and TRUNCATE empty data while keeping the table schema ready for future INSERTs; only DROP removes the table definition itself.

[HI] DELETE और TRUNCATE दोनों में टेबल ढांचा सुरक्षित रहता है और तुरंत नया INSERT किया जा सकता है; केवल DROP पूरी टेबल को मिटाता है।

Q8. In MySQL and Oracle, which of the three commands can be undone using ROLLBACK immediately after execution (without autocommit enabled)?

(MySQL और Oracle में (autocommit बंद होने पर) निष्पादन के तुरंत बाद किस कमांड को ROLLBACK द्वारा वापस पलटा जा सकता है?)

(A) TRUNCATE and DELETE

(B) DROP and TRUNCATE

(C) All three commands

(D) DELETE only

Correct Answer: (D)

[EN] In MySQL and Oracle, TRUNCATE and DROP are DDL statements that trigger an implicit COMMIT, leaving only DML DELETE rollback-safe.

[HI] MySQL और Oracle में TRUNCATE व DROP DDL होने से स्वतः कमिट हो जाते हैं; केवल DML DELETE ही ROLLBACK द्वारा वापस आ सकता है।

Q9. How do PostgreSQL and Microsoft SQL Server differ from Oracle/MySQL regarding ROLLBACK of TRUNCATE?

(TRUNCATE को ROLLBACK करने के मामले में PostgreSQL और MS SQL Server, Oracle/MySQL से कैसे भिन्न हैं?)

(A) SQL Server never supports ROLLBACK for any command

(B) Oracle allows rolling back DROP TABLE directly with ROLLBACK

(C) PostgreSQL forbids DELETE inside transactions

(D) PostgreSQL and SQL Server allow rolling back TRUNCATE (and DROP in PostgreSQL) if executed inside an explicit BEGIN transaction

Correct Answer: (D)

[EN] PostgreSQL and SQL Server treat DDL page deallocations transactionally inside explicit transaction blocks, whereas Oracle/MySQL auto-commit DDL.

[HI] PostgreSQL व SQL Server में यदि TRUNCATE एक BEGIN ट्रांज़ैक्शन ब्लॉक के भीतर चलाया गया हो, तो उसे भी ROLLBACK किया जा सकता है।

Q10. Which of the following is NOT true comparing DROP, TRUNCATE, and DELETE?

(DROP, TRUNCATE और DELETE की तुलना में निम्नलिखित में से कौन सा कथन सत्य नहीं है?)

(A) DELETE is a DML command while TRUNCATE and DROP are DDL commands

(B) DROP removes indexes, privileges, and table schema along with data

(C) TRUNCATE requires fewer privileges than DELETE because it leaves the table structure intact

(D) DELETE supports conditional filtering using WHERE

Correct Answer: (C)

[EN] TRUNCATE actually requires HIGHER privileges (such as DROP/ALTER/table ownership) than ordinary DML DELETE.

[HI] वास्तव में TRUNCATE के लिए सामान्य DELETE से अधिक उच्च (DDL/Alter/Drop) अधिकारों की आवश्यकता होती है, कम अधिकारों की नहीं।

Q11. After executing DROP TABLE Invoices, what occurs if you immediately run INSERT INTO Invoices VALUES (...)?

(DROP TABLE Invoices चलाने के तुरंत बाद INSERT INTO Invoices VALUES (...) चलाने पर क्या होगा?)

(A) The dropped rows are restored automatically

(B) A new Invoices table is created automatically

(C) The INSERT succeeds into an invisible shadow table

(D) An error occurs stating that table Invoices does not exist

Correct Answer: (D)

[EN] DROP deletes the table object completely from the catalog; you must run CREATE TABLE Invoices again before inserting.

[HI] DROP से कैटलॉग में टेबल का अस्तित्व ही मिट जाता है, इसलिए INSERT करने पर 'Table does not exist' त्रुटि आएगी।

Q12. Which command writes the LEAST amount of transaction log data when clearing a 10-million-row log table?

(1 करोड़ पंक्तियों वाली लॉग टेबल को खाली करते समय कौन सा कमांड सबसे कम ट्रांज़ैक्शन लॉग (Transaction Log) उत्पन्न करता है?)

(A) DELETE FROM LogTable;

(B) UPDATE LogTable SET msg = NULL;

(C) TRUNCATE TABLE (followed closely by DROP TABLE)

(D) DELETE FROM LogTable WHERE 1 = 1;

Correct Answer: (C)

[EN] TRUNCATE logs only extent/page deallocations rather than logging 10 million individual row images.

[HI] TRUNCATE 1 करोड़ पंक्तियों को अलग-अलग लॉग न करके केवल पेज डी-एलोकेशन लॉग करता है, अतः सबसे कम लॉग बनाता है।

Q13. Suppose a table holds 1,000 rows and a user runs DELETE FROM Employees; followed by ROLLBACK;. How many rows remain?

(यदि 1,000 पंक्तियों वाली Employees टेबल पर DELETE FROM Employees; चलाने के बाद ROLLBACK; कर दिया जाए (autocommit बंद है), तो कितनी पंक्तियाँ बचेंगी?)

(A) All 1,000 rows remain intact

(B) 500 rows remain

(C) 0 rows remain

(D) The table schema itself is dropped

Correct Answer: (A)

[EN] Because DELETE is DML and fully logged in Undo logs, ROLLBACK before COMMIT restores every deleted row.

[HI] चूँकि DELETE एक DML कमांड है और प्रत्येक पंक्ति Undo लॉग में दर्ज होती है, ROLLBACK सभी 1,000 पंक्तियों को वापस ले आएगा।

Q14. Why does SQL require DELETE FROM TableName instead of DELETE * FROM TableName in strict ANSI SQL?

(मानक ANSI SQL में DELETE * FROM TableName के बजाय DELETE FROM TableName क्यों लिखा जाता है?)

(A) Because '*' means drop schema in DELETE

(B) Because DELETE can only delete 1 column at a time

(C) Because '*' is reserved for DDL DROP

(D) DELETE always removes whole tuples (never single columns), so projecting '*' is invalid syntax in ANSI SQL

Correct Answer: (D)

[EN] Unlike SELECT (which projects chosen columns), DELETE always deletes complete rows, so ANSI SQL omits any column list or '*'.

[HI] SELECT कॉलम चुनता है इसलिए '*' लेता है, जबकि DELETE हमेशा पूरी पंक्ति (Tuple) हटाता है—अतः मानक SQL में DELETE के बाद '*' नहीं लिखा जाता।

Q15. Which command is ideal for a nightly ETL staging table where all yesterday's rows must be wiped fast before fresh loading while keeping indexes?

(नाइटली ETL स्टेजिंग टेबल का पुराना सारा डेटा तेजी से साफ करके इंडेक्स व स्कीमा बनाए रखते हुए नया डेटा भरने हेतु कौन सा कमांड सर्वश्रेष्ठ है?)

(A) DROP TABLE StagingData;

(B) DELETE FROM StagingData WHERE 1=1;

(C) TRUNCATE TABLE StagingData;

(D) ALTER TABLE StagingData DROP COLUMN *;

Correct Answer: (C)

[EN] TRUNCATE clears old rows near-instantly, frees pages, and preserves the table definition, indexes, and grants for the next load.

[HI] TRUNCATE कुछ मिलीसेकंड में पुराना डेटा हटा देता है और इंडेक्स व संरचना सुरक्षित रखता है, जिससे तुरंत नया लोड हो सके।

Q16. If a table had 3 indexes and 2 triggers, which command leaves all 3 indexes and 2 triggers untouched after removing all rows?

(यदि किसी टेबल पर 3 इंडेक्स और 2 ट्रिगर बने हैं, तो सारा डेटा हटाने के बाद भी कौन से कमांड उन सभी इंडेक्स व ट्रिगर्स को बनाए रखते हैं?)

(A) DROP only

(B) TRUNCATE only (DELETE drops triggers)

(C) Both DELETE and TRUNCATE (only DROP destroys them)

(D) DELETE only (TRUNCATE deletes indexes)

Correct Answer: (C)

[EN] TRUNCATE empties index leaf pages and skips firing triggers, yet keeps the index definitions and trigger definitions intact; DROP removes everything.

[HI] DELETE और TRUNCATE दोनों इंडेक्स व ट्रिगर की परिभाषा सुरक्षित रखते हैं; केवल DROP उन्हें नष्ट करता है।

Q17. Within DROP vs TRUNCATE vs DELETE in SQL, which sql command directly maps to: "DML; supports optional WHERE clause for selective removal"?

(DROP vs TRUNCATE vs DELETE in SQL में कौन सा SQL Command सीधे "DML; supports optional WHERE clause for selective removal" से संबंधित है?)

(A) DROP

(B) DELETE

(C) Empty-Child FK Rule

(D) TRUNCATE

Correct Answer: (B)

[EN] In DROP vs TRUNCATE vs DELETE in SQL, 'DELETE' handles 'DML; supports optional WHERE clause for selective removal' (Logs every row, fires ON DELETE triggers, keeps AUTO_INCREMENT and HWM).

[HI] DROP vs TRUNCATE vs DELETE in SQL में 'DELETE' का कार्य/विवरण 'DML; supports optional WHERE clause for selective removal' (Logs every row, fires ON DELETE triggers, keeps AUTO_INCREMENT and HWM) है।

Q18. Which option accurately describes 'TRUNCATE' in DROP vs TRUNCATE vs DELETE in SQL?

(DROP vs TRUNCATE vs DELETE in SQL के संदर्भ में 'TRUNCATE' की सही विशेषता कौन सी है?)

(A) DDL; deletes entire table schema, indexes, and data

(B) Parent table referenced by active child FOREIGN KEY

(C) DML; supports optional WHERE clause for selective removal

(D) DDL; removes ALL rows without supporting WHERE

Correct Answer: (D)

[EN] 'TRUNCATE' provides 'DDL; removes ALL rows without supporting WHERE' — key point: Minimal page log, skips triggers, resets AUTO_INCREMENT and HWM.

[HI] 'TRUNCATE' का मुख्य विवरण 'DDL; removes ALL rows without supporting WHERE' है (Minimal page log, skips triggers, resets AUTO_INCREMENT and HWM)।

Q19. In DROP vs TRUNCATE vs DELETE in SQL, identify the correct parameter for the specification: "DDL; deletes entire table schema, indexes, and data".

(DROP vs TRUNCATE vs DELETE in SQL में "DDL; deletes entire table schema, indexes, and data" विवरण किस विकल्प के लिए सही है?)

(A) DELETE

(B) Empty-Child FK Rule

(C) DROP

(D) TRUNCATE

Correct Answer: (C)

[EN] 'DROP' corresponds to 'DDL; deletes entire table schema, indexes, and data' (Removes object from catalog; destroys triggers, grants, and counters).

[HI] 'DROP' का संबंध 'DDL; deletes entire table schema, indexes, and data' (Removes object from catalog; destroys triggers, grants, and counters) से है।

Q20. Considering DROP vs TRUNCATE vs DELETE in SQL, what key behavior defines 'Empty-Child FK Rule'?

(DROP vs TRUNCATE vs DELETE in SQL में 'Empty-Child FK Rule' की मुख्य भूमिका या मान क्या है?)

(A) DDL; removes ALL rows without supporting WHERE

(B) DML; supports optional WHERE clause for selective removal

(C) Parent table referenced by active child FOREIGN KEY

(D) DDL; deletes entire table schema, indexes, and data

Correct Answer: (C)

[EN] 'Empty-Child FK Rule' represents 'Parent table referenced by active child FOREIGN KEY' (DELETE works row-wise (or cascades); TRUNCATE/DROP fail without CASCADE).

[HI] 'Empty-Child FK Rule' का अर्थ/मान 'Parent table referenced by active child FOREIGN KEY' है (DELETE works row-wise (or cascades); TRUNCATE/DROP fail without CASCADE)।

DROP vs TRUNCATE vs DELETE in SQL — Exam FAQs

Q1: Why did DELETE FROM BigTable take 10 minutes while TRUNCATE took 0.1 seconds?

DELETE FROM BigTable ने 10 मिनट क्यों लिए जबकि TRUNCATE 0.1 सेकंड में पूरा हो गया?

[EN] DELETE visits every row, updates every index leaf, runs triggers, and writes full row images to the transaction log for rollback. TRUNCATE simply marks the table's allocated data extents as free.

[HI] DELETE हर पंक्ति को पढ़कर इंडेक्स अपडेट करता है, ट्रिगर चलाता है और पूरा Undo लॉग लिखता है; जबकि TRUNCATE सीधे आवंटित डेटा ब्लॉक को खाली घोषित कर देता है।

Q2: Can TRUNCATE ever delete just half of a table?

क्या TRUNCATE से टेबल के केवल आधे या चुनिंदा रिकॉर्ड हटाए जा सकते हैं?

[EN] No. TRUNCATE has no WHERE clause and always removes 100% of rows in the table (or an entire table partition in partitioned tables). For conditional deletion, use DELETE.

[HI] नहीं। TRUNCATE में WHERE शर्त नहीं लगती और यह हमेशा पूरी टेबल का 100% डेटा हटाता है; शर्त आधारित डेटा हटाने के लिए केवल DELETE प्रयोग करें।

Q3: Does DELETE free disk space back to the operating system?

क्या DELETE चलाने से खाली हुई डिस्क स्पेस तुरंत ऑपरेटिंग सिस्टम को वापस मिल जाती है?

[EN] Usually no—deleted row slots remain inside the table's allocated pages/extents for future INSERT reuse. Reclaiming space back to the OS requires TRUNCATE, OPTIMIZE TABLE, or VACUUM FULL.

[HI] सामान्यतः नहीं—हटाई गई पंक्तियों की जगह आगे के INSERT के लिए टेबल के अंदर ही आरक्षित रहती है। डिस्क स्पेस वापस पाने के लिए TRUNCATE या OPTIMIZE/VACUUM FULL करना पड़ता है।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)