MySQL Delete Statement
MySQL DELETE statement allows you to delete existing records in a table within the database. By using delete statement, we can delete records on the basis of conditions.
Note: Be careful when deleting records in a database table! use WHERE clause, If you omit the WHERE clause, all records in the database table will be deleted!
MySQL DELETE TABLE Syntax
To detele data from existing table, use the following syntax:
DELETE FROM tablename WHERE Condition;
tablename: The table name from which you want to delete the data.
Condition: To check specific condition before delete the data. The conditions parameter is optional.
MySQL DELETE TABLE Data example
The following MySQL statement to delete the customer "Sunil Shetty" from "tblCustomerLoan" table:
DELETE FROM tblCustomerLoan WHERE firstName = 'Sunil' AND lastName = 'Shetty';
In the above example, we have deleted the record for customer "Sunil Shetty".
You can use MySQL Command Line Client to delete data from "tblCustomerLoan" table. It will look like this:
Show DELETE Data Example
You can check the deleted data from table by the following query:
SELECT * FROM tblCustomerLoan;
You can use MySQL Command Line Client to check the deleted data in table. It will look like this:
MySQL DELETE Data example for all records
The following MySQL statement to delete all records from "tblCustomerLoan" table:
DELETE FROM tblCustomerLoan;
DELETE * FROM tblCustomerLoan;