beginnerSQL Fundamentals — DDL, DML & Constraints
What is the difference between TRUNCATE and DELETE?
DELETE: DML, logged row-by-row, can have WHERE clause, fires triggers, respects foreign keys, can be rolled back, slow for large tables. TRUNCATE: DDL, minimal logging (deallocates data pages), no WHERE clause, does NOT fire per-row triggers (fires statement-level), may not respect foreign keys (check DB), faster (O(1) vs O(n)). PostgreSQL: TRUNCATE CAN be rolled back (transactional DDL). MySQL: T
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response