Explain the difference between DELETE, DROP, and TRUNCATE in SQLite.

Beginner

Answer

DELETE:

  • Removes specific rows based on WHERE clause
  • Can be rolled back in a transaction
  • Triggers fire for each deleted row
  • Auto-increment counters are not reset
DELETE FROM users WHERE age < 18;

DROP:

  • Removes entire table structure and data
  • Cannot be rolled back
  • Frees all storage space immediately
DROP TABLE users;

TRUNCATE:

  • SQLite doesn't support TRUNCATE command
  • Use DELETE FROM table_name to remove all rows
  • To reset auto-increment: DELETE FROM sqlite_sequence WHERE name='table_name'