What is the difference between DROP and TRUNCATE in SQL?
a) DROP removes the entire table, TRUNCATE removes all rows
b) TRUNCATE removes the table and its data, DROP removes only the rows
c) DROP removes indexes, TRUNCATE removes constraints
d) DROP removes rows based on a condition, TRUNCATE removes the structure
Answer:
a) DROP removes the entire table, TRUNCATE removes all rows
Explanation:
The DROP command is used to remove the entire table, including its structure, from the database. Once a table is dropped, it is permanently deleted along with its data and cannot be recovered unless backups are available.
TRUNCATE, on the other hand, removes all rows from a table but preserves the table structure. TRUNCATE is faster than DELETE because it does not generate individual row-level delete operations and often skips logging each row.
DROP is used when the table is no longer needed, while TRUNCATE is used to quickly clear all data from a table but retain its structure for future use.