MySQL DELETE

MySQL DELETE statement can be used to DELETE records from a Table.

MySQL DELETE Statement Syntax

Below is the Basic Syntax of MySQL DELETE Statement.

MySQL DELETE Statement Examples

To understand MySQL DELETE statement with extensive list of examples, let us create a Customer Table with sample data as shown in the following image by execute the following script.

mysql-delete-statement-demo-table

Example 1: MySQL DELETE Statement to Delete rows based on a condition.

If want to delete specific rows based on some condition then you need to add the WHERE clause to the DELETE statement. The below script deletes a Customer record from the Customer table whose CustomerId is 2.

RESULT:
mysql-delete-satement-example-1-result

Example 2 MySQL DELETE Statement to Delete All Rows.

If you don’t specify the WHERE condition in the DELETE Statement then it will remove all the rows/records from the Table. Be careful before executing any DELETE statement without a WHERE clause in it, as it will remove all the rows from the table and is an irreversible process.

Leave a Reply

Your email address will not be published. Required fields are marked *