Tools

SQL DELETE

Share:
Article Summary

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

ActionSyntax Example
Delete with conditionDELETE FROM table WHERE ...
Delete all rowsDELETE FROM table;
Fast delete (Oracle)TRUNCATE TABLE table_name;
Delete using subqueryDELETE WHERE col IN (SELECT ...)

โœ… Use DELETE to clean up dataโ€”carefully!

Was this helpful?

Written by

W3buddy
W3buddy

Explore W3Buddy for in-depth guides, breaking tech news, and expert analysis on AI, cybersecurity, databases, web development, and emerging technologies.