DELETE — Removing Rows
6 min read
Deleting Rows with DELETE
DELETE FROM removes rows from a table. Like UPDATE, it should almost always include a WHERE clause to target specific rows.
sql
-- Remove a specific student
DELETE FROM students WHERE id = 2;
-- Remove all enrolments for a course being retired
DELETE FROM enrolments WHERE course_id = 3;
-- Remove students with no enrolments
DELETE FROM students
WHERE id NOT IN (SELECT DISTINCT student_id FROM enrolments);If you want to remove all rows from a table quickly, most databases offer TRUNCATE TABLE tablename. It is much faster than a full-table DELETE because it does not log each row deletion individually.
A DELETE without WHERE empties the entire table and cannot be undone outside of a transaction. Use TRUNCATE intentionally or wrap the DELETE in a transaction so you can ROLLBACK if needed.
Ready to test yourself?
Practice SQL— quiz & coding exercises