DELETE (SQL Server Compact)

Removes rows from a table.

Syntax

DELETE 
   [ FROM ] table_name  
   [ WHERE < search_condition > ]

Arguments

  • FROM
    An optional keyword that can be used between the DELETE keyword and the target table_name.

  • table_name
    The name of the table that the rows are to be removed from.

  • WHERE
    Specifies the conditions that are used to limit the number of rows that are deleted.

  • <search_condition>
    Specifies the restricting conditions for the rows to be deleted. There is no limit to the number of predicates that can be included in a search condition.

Remarks

If a WHERE clause is not supplied, DELETE removes all the rows from the table.

If a search condition is specified, it is applied to each row of the table. All rows for which the result of the search condition is TRUE are marked for deletion.

The search condition is evaluated for each row of the table before any deletions occur.

All rows that are marked for deletion are deleted at the end of the DELETE statement before checking any integrity constraint.

The DELETE statement might fail if it violates a FOREIGN KEY constraint. If the DELETE statement removes multiple rows and any one of the removed rows violates a constraint, the statement is canceled, an error is returned, and no rows are removed.

Code Example

The following example deletes all rows from the Customers table.

DELETE Customers

The following example deletes all rows from the Customers table in which Company Nameis 'Wide World Importers'.

DELETE FROM Customers WHERE ([Company Name] = 'Wide World Importers')