DROP & TRUNCATE

DROP TABLE

DROP TABLE deletes a table: its structure, data, indexes and triggers.

DROP TABLE Shippers;

-- no error if it does not exist
DROP TABLE IF EXISTS Shippers;

Note: A table that other tables reference with a FOREIGN KEY cannot be dropped until those constraints are removed (or with CASCADE in PostgreSQL / Oracle).

TRUNCATE TABLE

TRUNCATE TABLE removes all rows but keeps the empty table. It is much faster than DELETE on large tables because it deallocates data pages instead of deleting row by row.

TRUNCATE TABLE OrderDetails;

Note: SQLite has no TRUNCATE; DELETE FROM table; without WHERE is optimized to do the same.

Which One?

  • Remove some rows: DELETE ... WHERE
  • Empty the table, keep it: TRUNCATE
  • Remove the table entirely: DROP