DELETE

DELETE#

Removes one or more rows from a table or view.

Syntax#

delete ::=

DELETE TOP ( n ) FROM table fromClausefromClause whereClausewhereClause optionClauseoptionClause

Click an element in the diagram to drill down to its definition.

Arguments#

TOP ( n )

Limits the statement to deleting n rows. The rows affected are arbitrary unless the order is otherwise constrained.

FROM

Optional keyword before the target; it has no effect on behavior.

table

The target table or view from which rows are removed.

FROM

An additional FROM clause used to qualify which rows to delete by joining the target with other tables or views.

WHERE

A WHERE search condition that restricts which rows are deleted. If it is omitted, every row is deleted.

OPTION

Query hints for the statement; see the OPTION clause.

Examples#

Delete selected rows:

DELETE FROM dbo.Product
WHERE  Discontinued = 1;

Delete using a join to another table:

DELETE p
FROM   dbo.Product p
JOIN   dbo.PurgeList l ON l.ProductId = p.Id;

Empty a table (remove all rows):

DELETE FROM dbo.StagingProduct;

See also