Syntax
DELETE [ TOP ( expression ) [ PERCENT ] ]
FROM table_expression
[ WHERE search_condition ]
[ OPTION ( query_hint [ ,...n ] ) ]
Description
The DELETE
statement removes rows from a table or view. It can be filtered with a WHERE
clause, limited with TOP
, or optimized with query hints.
Parameters
- TOP ( expression ) [ PERCENT ] – Limits the number of rows deleted.
PERCENT
treats the expression as a percentage of the total rows. - FROM table_expression – The target table or view. Aliases are allowed.
- WHERE search_condition – Optional filter to specify which rows to delete.
- OPTION ( query_hint ) – Optional query hints to influence the execution plan.
Remarks
- If
WHERE
is omitted, all rows are removed. - When deleting from a view, the view must be updatable.
- Triggers fire after rows are deleted.
- Use
OUTPUT
clause to capture deleted rows.
Examples
Delete a single row
DELETE FROM dbo.Employees
WHERE EmployeeID = 5;
Delete top 10 rows
DELETE TOP (10) FROM dbo.Logs
WHERE LogDate < '2023-01-01';
Delete 20% of rows
DELETE TOP (20) PERCENT FROM dbo.Sales
WHERE Region = 'West';
Delete with OUTPUT
DELETE FROM dbo.Orders
OUTPUT DELETED.OrderID, DELETED.OrderDate
WHERE OrderDate < '2022-01-01';