Removes rows from a table.
DELETE [ FROM ] table_name [ WHERE < search_condition > ]
- Is an optional keyword that can be used between the DELETE keyword and the target table_name.
- Is the name of the table from which the rows are to be removed.
- Specifies the conditions used to limit the number of rows that are deleted.
- 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.
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; and 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 prior to the checking of any integrity constraint.
The DELETE statement might fail if it violates a FOREIGN KEY constraint. If the DELETE 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.
A. Using DELETE with no parameters
The following example deletes all rows from the Customers table in the Northwind database.
B. Using DELETE on a set of rows
The following example uses the Customers table in the Northwind database. Because CompanyName may not be unique, the following example deletes all rows in which CompanyName is Eastern Connection.
DELETE FROM Customers WHERE CompanyName = 'Eastern Connection'