SQL DELETE
The DELETE statement is used to remove one or more rows from a table. πΉ Basic Syntax β οΈ Always use a WHERE clause to avoid deleting everything! πΉ Examples πΉ Delete All Rows (Be Cautious!) πΉ With Subqueries π§ Quick Recap Action Syntax Example Delete with condition DELETE FROM table WHERE ... Delete all rows […]
The DELETE statement is used to remove one or more rows from a table.
πΉ Basic Syntax
DELETE FROM table_name
WHERE condition;β οΈ Always use a WHERE clause to avoid deleting everything!
πΉ Examples
-- Delete a specific employee
DELETE FROM employees
WHERE employee_id = 101;
-- Delete all employees from the IT department
DELETE FROM employees
WHERE department = 'IT';πΉ Delete All Rows (Be Cautious!)
-- Delete all rows (but keep the table)
DELETE FROM employees;
-- Oracle tip: Use TRUNCATE for faster delete (no WHERE allowed)
TRUNCATE TABLE employees;πΉ With Subqueries
-- Delete employees who are not assigned to any department
DELETE FROM employees
WHERE department_id NOT IN (
SELECT id FROM departments
);π§ Quick Recap
| Action | Syntax Example |
|---|---|
| Delete with condition | DELETE FROM table WHERE ... |
| Delete all rows | DELETE FROM table; |
| Fast delete (Oracle) | TRUNCATE TABLE table_name; |
| Delete using subquery | DELETE WHERE col IN (SELECT ...) |
β
Use DELETE to clean up dataβcarefully!
Was this helpful?
Thanks for your feedback!