BeginnerCoder

Lesson 4 — UPDATE & DELETE

DELETE: remove rows carefully

DELETE FROM table WHERE condition removes the matching rows. cursor.rowcount tells you how many were removed. Like UPDATE, a DELETE without WHERE wipes the whole table. A safe habit: run the same WHERE as a SELECT first to see what would go.

SELECT COUNT(*) FROM carts WHERE abandoned = 1   -- check
DELETE FROM carts WHERE abandoned = 1            -- then delete

Why it matters: cleaning old data is routine, and "forgot the WHERE" is a famous way to lose a production table.

Want it another way?
Task

Write the DELETE that removes only expired sessions. Expected: 2 deleted, 2 left.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.