Skip to content

SQL DELETE Statement

Syntax

The DELETE statement in SQL is used to remove rows from a table. Use the WHERE clause to specify which rows to delete; omitting it deletes all rows.

-- Delete specific rows
DELETE FROM table_name
WHERE condition;
-- Delete all rows (use cautiously)
DELETE FROM table_name;

Example

-- Delete specific rows
DELETE FROM employees
WHERE name = 'John Doe';
/* Deletes the row:
| id | name | department | age |
|----|------------|------------|-----|
| 1 | John Doe | Sales | 35 |
*/
-- Delete rows based on a condition
DELETE FROM employees
WHERE age > 30;
/* Deletes:
| id | name | department | age |
|----|-------------|------------|-----|
| 3 | Alice Brown | General | 40 |
*/
-- Delete all rows from the table
DELETE FROM employees;
/* Deletes all rows, leaving the table structure intact:
| id | name | department | age |
|----|------------|------------|-----|
| (no rows) | | |
*/