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.
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';
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!
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.
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
Understanding rollback ability, log overhead, and triggers.
Automatic cascade deletion of dependent child table rows.
Undoing accidental deletions using ROLLBACK.
Archiving deleted records into historical audit log tables.