0
0
SQLquery~5 mins

Soft delete pattern concept in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the soft delete pattern in databases?
Soft delete is a technique where instead of removing a record from the database, a flag (like a boolean column) is set to mark it as deleted. This way, the data stays but is treated as deleted.
Click to reveal answer
beginner
Why use soft delete instead of hard delete?
Soft delete helps keep data for recovery, auditing, or historical reasons. It prevents accidental data loss by not physically removing records.
Click to reveal answer
beginner
How do you usually implement soft delete in a table?
Add a column like `is_deleted` or `deleted_at`. When deleting, update this column instead of removing the row. Queries then filter out rows marked as deleted.
Click to reveal answer
beginner
Write a simple SQL query to select only active (not deleted) records using soft delete.
SELECT * FROM table_name WHERE is_deleted = FALSE;
Click to reveal answer
intermediate
What is a common column type used to mark soft deleted records with a timestamp?
A column like `deleted_at` with a DATETIME or TIMESTAMP type is used. If it is NULL, the record is active; if it has a date, it means when it was deleted.
Click to reveal answer
What does the soft delete pattern do?
APermanently removes records from the database
BEncrypts records for security
CMarks records as deleted without removing them
DBacks up records to another database
Which column is commonly used to implement soft delete?
Apassword
Buser_id
Ccreated_at
Dis_deleted
How do you exclude soft deleted records in a query?
AWHERE is_deleted = TRUE
BWHERE is_deleted = FALSE
CORDER BY deleted_at DESC
DGROUP BY is_deleted
What is a benefit of soft delete?
AAllows data recovery after deletion
BImproves query speed by removing data
CAutomatically encrypts data
DPrevents all data changes
If a table uses a deleted_at column for soft delete, what does a NULL value mean?
ARecord is active (not deleted)
BRecord is deleted
CRecord is archived
DRecord is corrupted
Explain the soft delete pattern and why it is useful in databases.
Think about how you keep old emails in a trash folder instead of deleting them permanently.
You got /3 concepts.
    Describe how you would write a query to get only records that are not soft deleted.
    Remember, soft deleted records are marked, not removed.
    You got /2 concepts.