← Bank of America Interview Insights
Start by defining DELETE and TRUNCATE in terms of their SQL semantics, focusing on logging, transaction behavior, and performance. Then compare their use cases, especially in a banking context where data integrity and auditability are critical. Finally, recommend TRUNCATE for removing all rows when referential integrity and transactional logging are not required, but note that DELETE is safer in production environments with foreign keys or when you need to log the operation.
Pro tip: In a bank, always consider the audit trail and recovery implications: TRUNCATE is minimally logged and cannot be rolled back in some databases, so it might violate compliance requirements. Mention that you'd use TRUNCATE only after confirming with DBAs and ensuring no foreign key references, or use DELETE with a WHERE clause if you need to preserve the ability to rollback.
Explain that DELETE is a DML command that removes rows one by one, logs each deletion, can be rolled back, and can include a WHERE clause. It fires triggers and maintains referential integrity.
Explain that TRUNCATE is a DDL command that quickly removes all rows by deallocating data pages, minimally logs the operation, cannot be rolled back in some databases, and does not fire triggers. It resets identity columns and cannot be used with a WHERE clause.
Highlight differences in performance (TRUNCATE is faster), logging (DELETE logs each row, TRUNCATE logs page deallocations), transaction safety (DELETE can be rolled back, TRUNCATE may not be), and impact on triggers and foreign keys.
For removing all rows, TRUNCATE is generally preferred for speed and resource efficiency, but in a banking environment, consider audit requirements, foreign key constraints, and the need for rollback. If any of these are present, use DELETE or a staged approach.
Conclude with a clear rule: Use TRUNCATE when you need to quickly remove all rows and don't require transactional logging or rollback; use DELETE when you need conditional deletion, rollback capability, or to maintain referential integrity and audit trails.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.