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
✗ Incorrect
Soft delete marks records as deleted but keeps them in the database.
Which column is commonly used to implement soft delete?
Apassword
Buser_id
Ccreated_at
Dis_deleted
✗ Incorrect
The is_deleted column is often used as a flag for soft delete.
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
✗ Incorrect
Filtering with WHERE is_deleted = FALSE excludes deleted records.
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
✗ Incorrect
Soft delete allows recovering data since it is not physically removed.
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
✗ Incorrect
NULL in deleted_at means the record is still active.
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.
Practice
(1/5)
1. What is the main idea behind the soft delete pattern in databases?
easy
A. Marking data as deleted without actually removing it from the table
B. Permanently removing data from the database
C. Backing up data before deletion
D. Encrypting data before deletion
Solution
Step 1: Understand soft delete concept
Soft delete means we do not remove data but mark it as deleted.
Step 2: Compare options
Only Marking data as deleted without actually removing it from the table describes marking data instead of removing it.
Final Answer:
Marking data as deleted without actually removing it from the table -> Option A
Quick Check:
Soft delete = Mark data deleted, not remove [OK]
Hint: Soft delete means mark deleted, don't remove [OK]
Common Mistakes:
Thinking soft delete removes data physically
Confusing soft delete with backup
Assuming encryption is part of soft delete
2. Which of the following SQL table columns is commonly used to implement a soft delete?
easy
A. deleted_at TIMESTAMP
B. is_deleted BOOLEAN
C. delete_flag VARCHAR(10)
D. remove_date DATE
Solution
Step 1: Identify common soft delete column
The most common column is a boolean named is_deleted to mark true/false.
Step 2: Check other options
Other columns can be used but is_deleted BOOLEAN is standard and simplest.
Final Answer:
is_deleted BOOLEAN -> Option B
Quick Check:
Soft delete uses boolean flag = is_deleted [OK]
Hint: Soft delete uses boolean flag like is_deleted [OK]
Common Mistakes:
Using timestamp instead of boolean for soft delete
Choosing vague column names
Confusing soft delete with audit columns
3. Given the table users with a boolean column is_deleted, what will this query return?
SELECT * FROM users WHERE is_deleted = FALSE;
medium
A. Only users not marked as deleted
B. Only users marked as deleted
C. No users, syntax error
D. All users including deleted ones
Solution
Step 1: Understand the WHERE clause
The query filters rows where is_deleted is FALSE, meaning not deleted.
Step 2: Determine returned rows
Only users not marked deleted will be returned, excluding soft deleted rows.
Final Answer:
Only users not marked as deleted -> Option A
Quick Check:
WHERE is_deleted = FALSE returns active users [OK]
Hint: WHERE is_deleted = FALSE filters active rows [OK]
Common Mistakes:
Thinking it returns deleted users
Assuming syntax error due to boolean
Confusing TRUE and FALSE values
4. You have this query to select active users:
SELECT * FROM users WHERE is_deleted = 0;
But it returns no rows even though some users are active. What is the likely problem?
medium
A. The table has no data
B. The is_deleted column is missing
C. The query syntax is invalid
D. The column is_deleted uses TRUE/FALSE, not 0/1
Solution
Step 1: Check data type of is_deleted
If is_deleted is BOOLEAN, it expects TRUE/FALSE, not numeric 0/1.
Step 2: Understand why query returns no rows
Using 0 may not match FALSE in some SQL dialects, causing no rows returned.
Final Answer:
The column is_deleted uses TRUE/FALSE, not 0/1 -> Option D
Quick Check:
Boolean columns need TRUE/FALSE, not 0/1 [OK]
Hint: Boolean needs TRUE/FALSE, not 0/1 [OK]
Common Mistakes:
Assuming 0 equals FALSE in all SQL dialects
Ignoring data type of column
Thinking syntax error causes no rows
5. You want to implement soft delete on a products table. Which SQL statement correctly marks a product as deleted without removing it?
hard
A. INSERT INTO products (product_id, is_deleted) VALUES (10, TRUE);
B. DELETE FROM products WHERE product_id = 10;
C. UPDATE products SET is_deleted = TRUE WHERE product_id = 10;
D. SELECT * FROM products WHERE is_deleted = TRUE;
Solution
Step 1: Understand soft delete update
Soft delete means updating a flag, not deleting the row.
Step 2: Analyze each option
UPDATE products SET is_deleted = TRUE WHERE product_id = 10; updates is_deleted to TRUE for product 10, marking it deleted.
Final Answer:
UPDATE products SET is_deleted = TRUE WHERE product_id = 10; -> Option C
Quick Check:
Soft delete uses UPDATE to mark deleted [OK]
Hint: Use UPDATE to mark is_deleted TRUE [OK]
Common Mistakes:
Using DELETE instead of UPDATE
Trying to INSERT to mark deleted
Using SELECT instead of modifying data
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.