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';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;- 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
Exercise: MySQL Delete
What does the DELETE statement remove?