SQL DELETE
Statement
The DELETE statement is used to delete records in a table.
SQL DELETE Statement
The DELETE statement is used to delete rows in a table.
SQL DELETE Syntax
DELETE FROM table_name
WHERE condition;
Parameter Explanation:
- table_name: The name of the table from which to delete.
- condition: The deletion condition, specifying which data to delete.
| | Please note the WHERE clause in the SQL DELETE statement! <br>The WHERE clause specifies which record or records to delete. If you omit the WHERE clause, all records will be deleted! | | --- | --- |
Demo Database
In this tutorial, we will use the tutorialpro sample database.
Below is the data from the "Websites" table:
+----+--------------+---------------------------+-------+---------+
| id | name | url | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1 | Google | https://www.google.cm/ | 1 | USA |
| 2 | Taobao | https://www.taobao.com/ | 13 | CN |
| 3 | tutorialpro.org | http://www.tutorialpro.org/ | 4689 | CN |
| 4 | Weibo | http://weibo.com/ | 20 | CN |
| 5 | Facebook | https://www.facebook.com/ | 3 | USA |
+----+--------------+---------------------------+-------+---------+
SQL DELETE Example
Suppose we want to delete the website named "Facebook" and located in the USA from the "Websites" table.
We use the following SQL statement:
Example
DELETE FROM Websites
WHERE name='Facebook' AND country='USA';
After executing the above SQL, the data in the "Websites" table will look like this:
Delete All Data
You can delete all rows in a table without deleting the table itself. This means the table structure, attributes, and indexes will remain unchanged:
Note: Be very careful when deleting records! You cannot undo it!