bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL DELETE Statement

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind SQL DELETE Statement?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

DELETE ___ Customers
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Delete All Records
SQL DELETE Example
The SQL DELETE Statement

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 used in the examples:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

SQL DELETE Example

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

Example

DELETE FROM Customers
 WHERE CustomerName='Alfreds Futterkiste';

The selection from the "Customers" table will now look like this:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

Delete All Records

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

Syntax

DELETE FROM table_name ;

The following SQL deletes ALL records in the "Customers" table, without deleting the table:

Example

DELETE FROM Customers;

Delete a Table

To delete the table completely, use the DROP TABLE statement:

Syntax

DROP TABLE table_name ;

The following SQL drops the entire "Customers" table:

Example

Delete entire "Customers" table:

DROP TABLE Customers;

Previous

SQL UPDATE Statement

Next

SQL SELECT TOP, LIMIT and FETCH FIRST