Home page
 
 Home 
 ASP 
 PHP 
 SQL 
 HTML 
 JavaScript 
 Search 
 Contact 
 
Search
or browse popular tags
Subscription

Sign up for the free email newsletter for new tips, tutorials and more. Enter your email address below, and then click the button.

Privacy Policy

RSS Twitter

SQL: DELETE Statement

Print

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.




Tags:

Add To: Add to dzone dzone | Digg this digg | Add to del.icio.us del.icio.us | Stumble it stumbleupon

  • Comments





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