Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

SQL 

DELETE Statement
❮ PreviousNext ❯

The SQL DELETE Statement


The DELETE statement is used to delete existing records in a table.

DELETE Syntax
DELETE FROM table_name  WHERE condition;
Note: Be careful when deleting records in a table! Notice the WHERE clause in
the DELETE statement. The WHERE clause specifies which record(s) should be
deleted. If you omit the WHERE clause, all records in the table will be deleted!

Demo Database
Below is a selection from the "Customers" table in the Northwind sample
database:

CustomerID CustomerName ContactName Address City P


e

1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 1

2 Ana Trujillo Emparedados y Ana Trujillo Avda. de la Constitución México 0


helados 2222 D.F.
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México 0
D.F.

4 Around the Horn Thomas Hardy 120 Hanover Sq. London W

5 Berglunds snabbköp Christina Berguvsvägen 8 Luleå S


Berglund

SQL DELETE Example


The following SQL statement deletes the customer "Alfreds Futterkiste" from the
"Customers" table:

Example
DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';
Try it Yourself »

The "Customers" table will now look like this:

CustomerI CustomerName ContactName Address City P


D e

2 Ana Trujillo Emparedados y Ana Trujillo Avda. de la Constitución México 0


helados 2222 D.F.
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México 0
D.F.

4 Around the Horn Thomas Hardy 120 Hanover Sq. London W

5 Berglunds snabbköp Christina Berguvsvägen 8 Luleå S


Berglund

Delete All Records


It is possible to delete all rows in a table without deleting the table. This means
that the table structure, attributes, and indexes will be intact:

DELETE FROM table_name;

The following SQL statement deletes all rows in the "Customers" table, without
deleting the table:

Example
DELETE FROM Customers;
Try it Yourself »

Test Yourself With Exercises


Exercise:
Delete all the records from the Customers table where
the Country value is 'Norway'.
Customers
Country = 'Norway';

Submit Answer »

Start the Exercise

❮ PreviousNext ❯

COLOR PICKER

LIKE US
  

Get certified
by completing
a course today!

w3schoolsCERTIFIED.2021
Get started

CODE GAME

Play Game

REPORT ERROR
FORUM
ABOUT
SHOP

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference

Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples

Web Courses
HTML Course
CSS Course
JavaScript Course
Front End Course
SQL Course
Python Course
PHP Course
jQuery Course
Java Course
C++ Course
C# Course
XML Course
Get Certified »

W3Schools is optimized for learning and training. Examples might be simplified


to improve reading and learning. Tutorials, references, and examples are
constantly reviewed to avoid errors, but we cannot warrant full correctness of
all content. While using W3Schools, you agree to have read and accepted
our terms of use, cookie and privacy policy.

Copyright 1999-2021 by Refsnes Data. All Rights Reserved.


W3Schools is Powered by W3.CSS.

You might also like