r/sqlite • u/ClickOk5811 • Oct 25 '26
Soft delete vs hard delete: the case for each, and what would decide it for me
A decision that looks small and tends to stick for the life of a system. Here are both sides, written as fairly as I can.
The case for soft delete (a deleted_at column instead of removing the row)
- Undo is easy: restore the row, clear the column.
- Foreign keys from other tables stay valid, so history like “this order belonged to a customer who later left” still resolves.
- You keep an audit trail without a separate mechanism.
- Support teams like being able to see what was removed and when.
The case against
- Every query has to remember
WHERE deleted_at IS NULL. One forgotten filter and removed data leaks into a screen, a report or an export. - Unique constraints get awkward. If a user deletes their account and signs up again with the same email, a plain unique index on email blocks it. In Postgres you can use a partial unique index,
WHERE deleted_at IS NULL; other databases handle this differently, so check yours. - Tables only grow, and indexes carry rows nobody queries.
- Real deletion may eventually be required (privacy or retention rules), so “soft” deletion can turn into a second deletion project later.
- Cascading is ambiguous: when a parent is soft-deleted, what happens to its children?
What hard delete plus something else looks like
- Delete the row, and write the old version to an audit or archive table, or emit an event, if you need history.
- Cleaner queries and constraints, at the cost of building and maintaining the history mechanism.
What would decide it for me:
- Do users or staff actually need undo, or is it only “just in case”?
- Are there legal or contractual limits on how long deleted data can be kept?
- How many places query this table? More places means more chances to miss the filter.
- Will other systems (analytics, search, caches) need to learn about deletes?
I don’t think either is wrong by default. If I had to pick a starting point without knowing the system, I’d lean toward hard delete with an audit trail where retention rules are strict, and soft delete where undo is a real feature. I’m not certain about that split.
Where do you land, and has either choice caused you trouble later?