Challenge - 5 Problems
Soft Delete Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Identify active records with soft delete
Given a table
users with columns id, name, and deleted_at (which is NULL if the record is active), which query returns only active users?SQL
SELECT * FROM users WHERE deleted_at IS NULL;
Attempts:
2 left
💡 Hint
Think about how soft delete marks records as deleted by setting a timestamp.
✗ Incorrect
Soft delete means marking a record as deleted by setting a timestamp in
deleted_at. Active records have deleted_at as NULL.🧠 Conceptual
intermediate2:00remaining
Purpose of soft delete timestamp
Why do we use a
deleted_at timestamp column in soft delete instead of just deleting the record?Attempts:
2 left
💡 Hint
Think about why we might want to keep deleted data around.
✗ Incorrect
Soft delete keeps data by marking it deleted with a timestamp, allowing recovery or audit later.
📝 Syntax
advanced2:00remaining
Correct SQL to soft delete a record
Which SQL statement correctly soft deletes a user with
id = 5 by setting deleted_at to the current timestamp?Attempts:
2 left
💡 Hint
Soft delete means updating the timestamp, not deleting the row.
✗ Incorrect
Soft delete updates the
deleted_at column to the current time for the target record.❓ optimization
advanced2:00remaining
Optimizing queries with soft delete
To improve performance of queries filtering active records (
deleted_at IS NULL), which index is best to add?Attempts:
2 left
💡 Hint
Think about which column is used in the WHERE clause to filter active records.
✗ Incorrect
Indexing
deleted_at speeds up filtering active (non-deleted) records by that column.🔧 Debug
expert2:00remaining
Why does this soft delete query fail to exclude deleted records?
Consider this query to select active users:
Why does it not return any rows even if some users are active?
SELECT * FROM users WHERE deleted_at = NULL;Why does it not return any rows even if some users are active?
Attempts:
2 left
💡 Hint
Remember how SQL treats NULL comparisons.
✗ Incorrect
In SQL, NULL is not equal to anything, even NULL. Use IS NULL to check for NULL values.