DELETE
ELI5 — The Vibe Check
DELETE removes rows from a table. It is the 'Delete' in CRUD. Like UPDATE, you MUST use a WHERE clause — without it, you delete everything in the table. Always double-check before running DELETE in production.
Real Talk
DELETE is the SQL statement for removing rows from a table. A WHERE clause filters which rows are deleted. Without WHERE, all rows are deleted (though the table structure remains). Foreign key constraints with ON DELETE CASCADE can cause cascading deletions in related tables.
Show Me The Code
-- Be very careful!
DELETE FROM sessions
WHERE expires_at < NOW();
-- Nuclear option (without WHERE):
-- DELETE FROM sessions; -- DELETES EVERYTHING
When You'll Hear This
"DELETE old sessions that expired more than 30 days ago." / "I ran DELETE without a WHERE clause on production."
Related Terms
CRUD (Create, Read, Update, Delete)
CRUD is the four things you can do to data: Create it, Read it, Update it, Delete it. Literally every app ever made is just CRUD in a trenchcoat.
INSERT
INSERT is how you add new data to a database. It is the 'Create' in CRUD. You tell it which table, which columns, and what values to put in.
SELECT
SELECT is how you ask a database to give you data. It is the 'Read' in CRUD.
UPDATE
UPDATE changes existing data in a table. It is the 'Update' in CRUD.
WHERE
WHERE is how you filter which rows a query affects. Without WHERE, SELECT returns everything, UPDATE changes everything, DELETE deletes everything.