Q42: What is the difference between Soft Delete and Hard Delete?
- Hard Delete: Removes rows permanently from the physical storage layer using
DELETE FROM table. Cannot be undone except by restoring database backups. - Soft Delete: Flags records as deleted without removing them physically, typically using a flag or timestamp column (
is_deleted BOOLEAN,deleted_at TIMESTAMP).
Soft Delete Considerations
Soft deletes preserve historical data and support simple record restoration, but require all application queries to include WHERE deleted_at IS NULL filters.
Key Takeaways
- Soft deletes flag records as inactive without removing physical data.
- Soft deletes require consistent filtering (
deleted_at IS NULL) across application queries or database views.