Explain the difference between DELETE, TRUNCATE, and DROP.

Beginner

Answer

  • DELETE: Removes specific rows based on conditions, can be rolled back, triggers fire
  • TRUNCATE: Removes all rows quickly, can be rolled back, triggers don't fire
  • DROP: Removes the entire table structure and data, cannot be rolled back
DELETE FROM users WHERE age < 18;  -- Removes specific rows
TRUNCATE TABLE users;              -- Removes all rows
DROP TABLE users;                  -- Removes table entirely