Suppose we have this table employees
:
id | name | salary | |
---|---|---|---|
1 | Alice Johnson | alice.johnson@example.com | 60000 |
2 | Bob Smith | bob.smith@example.com | 55000 |
3 | Carol Lee | carol.lee@example.com | 70000 |
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:
id | name | salary | |
---|---|---|---|
1 | Alice Johnson | alice.johnson@example.com | 60000 |
3 | Carol Lee | carol.lee@example.com | 70000 |
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:
id | name | salary | |
---|---|---|---|
1 | Alice Johnson | alice.johnson@example.com | 60000 |
Important:
- Always use
WHERE
to avoid deleting all rows unintentionally. - Use a
SELECT
query after deletion to verify changes.