Deleting Data from Tables (DELETE)

Suppose we have this table employees:

idnameemailsalary
1Alice Johnsonalice.johnson@example.com60000
2Bob Smithbob.smith@example.com55000
3Carol Leecarol.lee@example.com70000

Example 1: Delete one employee by id

DELETE FROM employees
WHERE id = 2;

Note: This command does not produce output but returns the number of rows deleted.

After deletion, the table will look like:

idnameemailsalary
1Alice Johnsonalice.johnson@example.com60000
3Carol Leecarol.lee@example.com70000

Example 2: Delete employees with salary less than 60000

DELETE FROM employees
WHERE salary < 60000;

Note: This command does not produce output but returns the count of deleted rows.

After deletion, the table will look like:

idnameemailsalary
1Alice Johnsonalice.johnson@example.com60000

Important:

  • Always use WHERE to avoid deleting all rows unintentionally.
  • Use a SELECT query after deletion to verify changes.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top