SQL DELETE

DELETE permanently deletes rows from a table.

DELETE can delete one or more records in a table.

Use the WHERE clause to DELETE only specific records.

Example

#

Remove customer Elizabeth Lincoln who lives in Canada.

DELETE Customer
 WHERE FirstName = 'Elizabeth' 
   AND LastName = 'Lincoln'
   AND Country = 'Canada'

Be sure to include a WHERE clause or else all records are deleted from the table.

Syntax

DELETE syntax.

DELETE table-name 

DELETE syntax with WHERE.

DELETE table-name 
 WHERE condition

More Examples

SQL DELETE

PRODUCT
Id
ProductName
SupplierId
UnitPrice
Package
IsDiscontinued
Problem: Remove all products.
DELETE Product
Result: 77 records deleted.

SQL DELETE WHERE

PRODUCT
Id
ProductName
SupplierId
UnitPrice
Package
IsDiscontinued
Problem: Remove products over $50.
DELETE Product
 WHERE UnitPrice > 50
Result: 7 records deleted.

SQL DELETE single record

CUSTOMER
Id
FirstName
LastName
City
Country
Phone
Problem: Remove customer with Id = 21.
DELETE Customer
 WHERE Id = 21

This is a common scenario in which a single record is deleted.

Result: 1 record deleted.

You may also like



Guides


vsn 3.1