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

Basic Syntax

DELETE FROM table_name
WHERE condition;
  • table_name → The table to delete from
  • WHERE → Filters which rows to delete

Without WHERE, all rows will be deleted!

2.Example Table

Employees Table

EmployeeID Name Department Salary
1 John IT 5000
2 Jane HR 4500
3 Mike IT 6000

3.Delete a Single Row

DELETE FROM Employees
WHERE EmployeeID = 2;

Result: Jane’s record is removed.

4.Delete Multiple Rows

DELETE FROM Employees
WHERE Department = 'IT';

Result: All employees in IT department are removed.

5.Delete All Rows

DELETE FROM Employees;
  • Removes all rows from the table
  • Table structure and columns remain intact
  • ⚠ Be careful; use TRUNCATE for faster deletion if needed

6.Delete Using JOIN

DELETE e
FROM Employees e
INNER JOIN ResignedEmployees r
    ON e.EmployeeID = r.EmployeeID;
  • Deletes rows in Employees that match ResignedEmployees table

7.Delete Using Subquery

DELETE FROM Employees
WHERE EmployeeID IN (
    SELECT EmployeeID FROM Employees WHERE Department = 'HR'
);
  • Deletes rows based on a subquery

8.Delete With TOP

DELETE TOP (2) FROM Employees
WHERE Department = 'IT';
  • Deletes only the first N rows that meet the condition
  • Useful for batch deletes

9.Transaction with DELETE

BEGIN TRAN;
DELETE FROM Employees WHERE Department = 'IT';
ROLLBACK;  -- Undo changes
-- COMMIT; -- To save changes

Categorized in:

SQL Server,