DELETE (Transact‑SQL)

On this page

Syntax

DELETE [TOP (expression) [PERCENT]] 
FROM 
    { 
        <object> 
        | <derived_table> 
        | <table_variable> 
    } 
    [WITH ( <table_hint> [ ,…n ] )] 
    [WHERE <search_condition> ] 
    [OPTION ( <query_hint> [ ,…n ] ) ]
        

The DELETE statement removes rows from a table or view.

Parameters

ParameterDescription
TOP (expression) [PERCENT]Limits the number of rows deleted.
FROM <object>The target table, view, or derived table.
WITH (table_hint)Specifies table hints such as ROWLOCK.
WHERE <search_condition>Filters the rows to be deleted.
OPTION (query_hint)Applies query hints like MAXDOP.

Examples

Delete all rows from a table

DELETE FROM dbo.Customers;

Delete rows with a condition

DELETE FROM dbo.Orders
WHERE OrderDate < '2020-01-01';
        

Delete the top 10 rows

DELETE TOP (10) FROM dbo.Logs
WHERE LogLevel = 'Debug';
        

Delete using a join

DELETE t
FROM dbo.Employee AS e
JOIN dbo.Timesheet AS t ON e.EmployeeID = t.EmployeeID
WHERE e.Status = 'Terminated';
        

Remarks

See also