← Back
LESSON 15
SQL (Core) - Deleting rows
Prereq: None | Progress: 0%
Course Syllabus
Lesson 0 📖 What is SQL? Lesson 1 📖 SELECT queries 101 Lesson 2 📖 Queries with constraints (Pt. 1) Lesson 3 📖 Queries with constraints (Pt. 2) Lesson 4 📖 Filtering & sorting results Review 1 📖 Simple SELECT Queries Lesson 6 📖 Multi-table queries with JOINs Lesson 7 📖 OUTER JOINs Lesson 8 📖 A short note on NULLs Lesson 9 📖 Queries with expressions Lesson 10 📖 Queries with aggregates (Pt. 1) Lesson 11 📖 Queries with aggregates (Pt. 2) Lesson 12 📖 Order of execution of a Query Lesson 13 📖 Inserting rows Lesson 14 📖 Updating rows Lesson 15 📖 Deleting rows Lesson 16 📖 Creating tables Lesson 17 📖 Altering tables Lesson 18 📖 Dropping tables Lesson 19 📖 Subqueries & Nested Queries Lesson 20 📖 Set Operations Summary 🎓 Course Completion
SQL Lesson 15: Deleting rows
When records are obsolete, corrupted, or no longer needed, you remove them using the DELETE FROM statement.
1. Targeted Row Deletion Syntax
Specify the target table and a precise filtering condition identifying the target rows to purge:
DELETE FROM movies
WHERE year < 2005;
2. Hard Deletes vs. Soft Deletes
Running DELETE FROM removes records permanently (hard delete). Many enterprise production systems prefer soft deletes by setting a flag column like UPDATE users SET is_active = false WHERE id = 10; so historical records can be audited or restored later.
⚠️
DELETE Safety Tip
Before running a DELETE statement, execute a SELECT * FROM table WHERE condition; using the exact same WHERE filter to preview which rows will be removed!
🗄️ Schema Explorer SELECTABLE
› movies
|
🎯 Exercises Checklist:
☐ 1. Delete all movies that were released before 2005
☐ 2. Delete all movies directed by Andrew Stanton
⚡ Practice Console
💡 Hint:
Loading hint...
🔑 Solution SQL:
SELECT * FROM movies; Data Output
No results. Run query to fetch data.