DELETE
deletes qualifying rows
What changes
- Input
- target table, optional FROM/JOIN sources, WHERE
- Output or change
- removes rows from one target
Syntax at a glance
[ WITH <common_table_expression> [ ,...n ] ] DELETE [ TOP ( expression ) [ PERCENT ] ] [ FROM ] { { table_alias | <object> | rowset_function_limited [ WITH ( table_hint_limited [ ...n ] ) ] } | @table_variable } [ <OUTPUT Clause> ] [ FROM table_source [ ,...n ] ] [ WHERE { <search_condition> | { [ CURRENT OF { { [ GLOBAL ] cursor_name } | cursor_variable_name } ] } } ] [ OPTION ( <Query Hint> [ ,...n ] ) ] [; ]
Work example
A specific set of rows should be removed while the remaining set stays available.
Run the sample against its table variable. Preview the predicate with SELECT and confirm the expected row count before DELETE.
Check your work DELETE. Id 1 is absent and Id 2 remains. The sample changes no permanent data.
Practice SQL
Open in SQL FlowDECLARE @Scores TABLE (Id int, Points int);
INSERT @Scores (Id, Points) VALUES (1, 12), (2, 18);
DELETE FROM @Scores WHERE Id = 1;
SELECT Id, Points FROM @Scores ORDER BY Id;
Open Microsoft Learn for full syntax, permissions, and details for your version.