SQL - MySQL

Module 01 - Database Theory
1. Introduction to Databases2. DBMS Theory Concepts3. Types of Keys4. Database Relationships5. DBMS Interview Questions
Module 02 - CRUD Operations
1. Create - INSERT2. Read - SELECT3. Update - UPDATE4. Delete - DELETE5. Alter - ALTER TABLE
MySQL Playground
Profile
Akkal DhamiFull Stack Developer

Building modern web experiences with a focus on performance, scalability, and clean architecture.

© 2026 | Akkal Dhami | All rights reserved

Built with
byAkkal Dhami

Navigation

  • Projects
  • Dev Setup
  • Playbook
  • Templates
  • Networking
  • SQL - MySQL
  • SQL Playground
  • DSA
AKKAL DHAMIAKKAL DHAMIAKKAL DHAMI

Delete - DELETE

DELETE removes rows from a table. Same rule as UPDATE: always pair it with WHERE, or it removes every row.


Basic syntax

example.sql
DELETE FROM table_name
WHERE condition;

Deleting one row

example.sql
DELETE FROM books
WHERE title = 'Brave New World';

Deleting multiple rows

Any row matching the condition gets removed:

example.sql
DELETE FROM books
WHERE in_stock = FALSE;

The most important rule

Leaving off WHERE deletes every row in the table:

example.sql
-- Danger: this deletes ALL books
DELETE FROM books;

The table itself still exists afterward — just empty. Compare that to DROP TABLE books;, which removes the table's structure entirely.


Preview before you delete

Run the same condition as a SELECT first, so you know exactly what's about to disappear:

example.sql
SELECT * FROM books WHERE in_stock = FALSE;

If that returns the rows you expect, swap it for DELETE.


DELETE vs TRUNCATE vs DROP

CommandWhat it doesKeeps table structure?
DELETERemoves specific rows matching a conditionYes
TRUNCATERemoves all rows, resets auto-incrementYes
DROPDeletes the table entirely, structure includedNo

TRUNCATE is faster than a DELETE with no WHERE, but it can't be filtered — it always removes everything:

example.sql
TRUNCATE TABLE books;

MySQL's safety net

Just like UPDATE, MySQL's "safe update mode" can block a DELETE that doesn't reference a key column in WHERE (Error 1175). That's intentional protection against accidental mass deletes.


Quick Reference

GoalExample
Delete one rowDELETE FROM books WHERE title = 'Brave New World';
Delete multiple rowsWHERE in_stock = FALSE
Preview before deletingRun the same WHERE as a SELECT first
Wipe all rows, keep tableTRUNCATE TABLE books;
Remove table entirelyDROP TABLE books;
delete-reference.sql
-- Deleting one row
DELETE FROM books
WHERE title = 'Brave New World';
 
-- Deleting multiple rows
DELETE FROM books
WHERE price > 15;
 
-- Deleting all rows (be careful!)
DELETE FROM books;