MySQL SQL

MySQL DELETE

The MySQL DELETE Statement

To remove already-existing entries from a table, use the DELETE statement.

DELETE Syntax

				
					DELETE FROM table_name WHERE condition;
				
			

Note: Exercise caution while removing entries from a table! Take note of the DELETE statement’s WHERE clause. Which record or records should be deleted is specified in the WHERE clause. Every record in the table will be removed if the WHERE clause is left out!

Demo Database

Below is a selection from the “Customers” table in the Northwind sample database:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1

Alfreds 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
4

Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

SQL DELETE Example

The customer “Alfreds Futterkiste” is removed from the “Customers” table using the SQL statement that follows:

Example

				
					DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';
				
			

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
4

Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

Delete All Records

A table can have all of its rows removed without the table itself being removed. This implies that the characteristics, indexes, and table structure will all 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;
				
			
Share this Doc

MySQL DELETE

Or copy link

Explore Topic