What is the difference between soft delete and hard delete?
Why Interviewers Ask This
This tests whether you can apply MySQL / SQL knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
Hard delete permanently removes a row from the database using DELETE. The data is gone and cannot be recovered (without backups). Soft delete marks a row as deleted without actually removing it, typically by adding a deleted_at TIMESTAMP NULL or is_deleted TINYINT(1) DEFAULT 0 column. The row remains in the database but is excluded from application queries. Implementation: UPDATE users SET deleted_at = NOW() WHERE id = ?;. All queries must then filter: WHERE deleted_at IS NULL. Benefits of soft delete: (1) Data recovery — "undelete" by setting deleted_at to NULL; (2) Audit trail — know what was deleted and when; (3) Referential integrity — related data (orders for a deleted user) remains intact; (4) Analytics — deleted records contribute to historical reports. Drawbacks: (1) Every query must include the soft-delete filter (easy to forget — can expose deleted data); (2) Table grows indefinitely — need archival strategy; (3) UNIQUE constraints still apply to soft-deleted rows (a deleted email blocks reuse — use composite unique on (email, deleted_at) or handle in application). Frameworks like Laravel's SoftDeletes trait automate this pattern.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last MySQL / SQL project, I used this when...' immediately makes your answer more credible and memorable.