Home page   WebCheatSheet.com


SQL: DELETE Statement


The Delete statement allows you to delete a single record or multiple records from a table. After you remove records using a Delete statement, you cannot undo the operation. To check which records will be deleted, examine the results of a Select query that uses the same criteria. It is also important to understand, that a Delete statement deletes entire records, not just data in specified fields. If you just want to delete certain fields, use an Update query that changes the value to Null.

The syntax for the Delete statement is as follows:

DELETE FROM table_name
WHERE conditions

Example #1

DELETE FROM EmployeeAddressTable

This example demonstrates how to totally empty a table of all records while leaving the table structure and properties, such as attributes and indexes, intact.

Example #2

DELETE
FROM Orders
WHERE OwnerID=64

This example is more specific and only deletes those records that meet certain criteria.

Example #3

DELETE
FROM Antiques
WHERE exists
(
select orders.ItemDesired
from orders
where
orders.OwnerID=Antiques.ItemID and
Orders.ItemDesired="Bookcase"
)

This would delete all records in the Antiques table where there is a record in the orders table whose ItemDesired is Bookcase, and the OwnerID is the same as the ItemID.



Copyright © 2005-2007 www.WebCheatSheet.com All Rights Reserved.