Class 22 of 58 • Data Manipulation & Querying (DML & DQL)

SQL DELETE Statement: Record Deletion & Soft-Delete Patterns

The DELETE statement removes one or more existing rows from a table based on a filter condition. As a DML operation, DELETE can be rolled back inside a database transaction, fires row-level triggers, and records every removed row in the database undo log.


Standard DELETE Syntax

DELETE FROM table_name
WHERE filter_condition;
-- Delete specific student by primary key
DELETE FROM students
WHERE student_id = 5;

-- Delete inactive students enrolled prior to 2020
DELETE FROM students
WHERE is_active = FALSE AND enrollment_date < '2020-01-01';

The Industry "Soft Delete" Pattern

In production financial, healthcare, and enterprise software, hard-deleting records is strictly prohibited due to legal audit compliance. Instead, engineers implement Soft Deletes:

-- Add a soft-delete column
ALTER TABLE students ADD COLUMN is_deleted BOOLEAN DEFAULT FALSE;

-- Instead of DELETE, run an UPDATE:
UPDATE students
SET is_deleted = TRUE
WHERE student_id = 3;

-- Application queries simply filter active records:
SELECT * FROM students WHERE is_deleted = FALSE;

Congratulations! You have completed Module 3 (Data Manipulation). Now let us advance to Module 4 and learn pattern matching starting with SQL LIKE & Wildcards!


Frequently Asked Questions (FAQ)

A Hard Delete executes DELETE FROM table, permanently erasing the row from disk. A Soft Delete does not delete the row; instead, it sets an 'is_deleted = TRUE' or 'deleted_at = NOW()' flag so the record can be hidden while preserving audit history.

Yes! If executed inside an active transaction (BEGIN; DELETE FROM table WHERE ...; ROLLBACK;), all deleted rows are completely restored from the undo log.

If a parent table has a foreign key configured with ON DELETE CASCADE, deleting a row from the parent table automatically deletes all matching referencing rows in child tables.

Next Step in Your SQL Database Learning Path:

Proceed to the next class in sequence to build production mastery of relational database architecture.

Continue to Class 23: LIKE & Wildcards → Previous: ← UPDATE Statement | Full Syllabus


Related SQL Masterclass Lessons & Recommended Next Topics

DELETE vs TRUNCATE →

Understanding rollback ability, log overhead, and triggers.

ON DELETE CASCADE →

Automatic cascade deletion of dependent child table rows.

Transactions & Rollback →

Undoing accidental deletions using ROLLBACK.

Audit Triggers on DELETE →

Archiving deleted records into historical audit log tables.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!