MySQL Delete

The DELETE statement removes existing records from a table, and just like UPDATE, forgetting the WHERE clause can wipe out far more data than intended.

The DELETE Statement Syntax

DELETE FROM removes one or more rows from a table based on a condition. Its syntax is simpler than UPDATE because there is no SET clause — you only specify the table and, ideally, a WHERE clause describing which rows should be removed.

Basic DELETE syntax

DELETE FROM table_name
WHERE condition;

Deleting a Specific Row

The safest and most common use of DELETE targets a single row via its primary key, such as removing a specific customer record that a business no longer needs to retain.

Delete one customer by primary key

DELETE FROM Customers
WHERE CustomerID = 24;

Deleting a Group of Rows

WHERE conditions in DELETE work exactly as they do in SELECT and UPDATE, so you can remove an entire category of rows in one statement, such as clearing out all customers associated with a discontinued region.

Delete all customers from a discontinued country

DELETE FROM Customers
WHERE Country = 'Atlantis';
Note: DELETE FROM table_name without a WHERE clause removes every row in the table permanently, and this action normally cannot be undone unless you are inside a transaction that has not yet been committed.

Deleting All Rows in a Table

It is possible to intentionally empty a table while keeping its structure intact, by running DELETE FROM without any WHERE clause. This is sometimes done on purpose, such as clearing out a staging table between batch loads, but it should always be a deliberate, confirmed decision.

Intentionally remove every row (structure remains)

DELETE FROM Customers;
Note: If your goal is specifically to wipe an entire table quickly and you don't need to log individual row deletions, TRUNCATE TABLE table_name; is typically faster than an unqualified DELETE, though it also resets auto-increment counters.
  • DELETE FROM removes rows; the table itself, its columns, and indexes remain
  • Always include WHERE unless you deliberately want to empty the table
  • DELETE can be rolled back inside a transaction if it hasn't been committed
  • TRUNCATE TABLE is a faster alternative for wiping an entire table but is not row-conditional
StatementEffect
DELETE FROM t WHERE id = 5;Removes only the matching row
DELETE FROM t;Removes every row, keeps table structure
TRUNCATE TABLE t;Empties table fast, resets auto-increment
DROP TABLE t;Deletes the entire table and its structure

Exercise: MySQL Delete

What does the DELETE statement remove?