SQLDELETE Clause

DELETE Query

The DELETE statement in SQL is used to remove rows from a table.

You can delete:

  • A single row
  • Multiple rows
  • All rows (if used without WHERE — with caution)

Basic Syntax

DELETE FROM table_name
WHERE condition;
  • DELETE FROM: specifies the table you want to delete rows from

  • WHERE: filters which rows will be deleted

    • If you omit WHERE, all rows in the table will be deleted

Example Table: students

idnameageemailenrollment_date
1Alice Smith20alice@example.com2025-06-23
2Bob Johnson22bob@example.com2025-06-20
3Carol Thomas19carol@example.com2025-06-21
4Dan Green23dan@example.com2025-06-19

Example 1: Delete One Row

Delete the student with id = 3:

DELETE FROM students
WHERE id = 3;

Example 2: Delete Rows Matching a Condition

Delete all students older than 22:

DELETE FROM students
WHERE age > 22;

Example 3: Delete All Rows (No WHERE)

Caution: This will remove all rows from the table:

DELETE FROM students;

The table will still exist, but it will be empty.


Important Notes

  • Always use WHERE unless you are absolutely sure you want to delete all rows.
  • Once rows are deleted, the data cannot be recovered unless a backup exists.
  • If you only want to temporarily “hide” data instead of deleting it, consider using an is_active column instead of physically deleting rows.

Summary

  • DELETE removes rows from a table.
  • WHERE filters which rows to delete — be careful when using DELETE.
  • If WHERE is omitted, all rows will be deleted.
  • Deleting data is permanent — use backups and test carefully.