SQL DELETE
DELETE statement is used to delete records from a table.
SQL DELETE statement
The DELETE statement is used to delete rows from a table.
SQL DELETE syntax
DELETE FROM table_name
WHERE some_column=some_value;
WHERE some_column=some_value;
Please pay attention to the WHERE clause in the SQL DELETE statement! The WHERE clause specifies which record or records need to be deleted. If you omit the WHERE clause, all records will be deleted! |
Demo Database
In this tutorial, we will use the php sample database.
The following is the data selected from the "Websites" table:
+----+--------------+--- ------------------------+------+---------+
| id | name | url --------+-------+---------+
| 1 | Google | https://www.google.cm/ | 1 | USA |
| 2 | Taobao | https://www.taobao.com/ | 13 | CN |
| 3 | php Chinese website | //m.sbmmt.com/ | 4689 | CN |
| 4 | Weibo | http://weibo.com/ | 20 | CN |
| 5 | Facebook | https://www.facebook.com/ | 3 | USA |
| 6 | Baidu | https://www.baidu.com/ | 4 | CN |
| 7 | stackoverflow | http://stackoverflow.com/ | 0 | IND |
+----+---- ----------+--------------------------+-------+-- -------+
| id | name | url --------+-------+---------+
| 1 | Google | https://www.google.cm/ | 1 | USA |
| 2 | Taobao | https://www.taobao.com/ | 13 | CN |
| 3 | php Chinese website | //m.sbmmt.com/ | 4689 | CN |
| 4 | Weibo | http://weibo.com/ | 20 | CN |
| 5 | Facebook | https://www.facebook.com/ | 3 | USA |
| 6 | Baidu | https://www.baidu.com/ | 4 | CN |
| 7 | stackoverflow | http://stackoverflow.com/ | 0 | IND |
+----+---- ----------+--------------------------+-------+-- -------+
SQL DELETE ExampleSuppose we want to delete the website name "Baidu" and the country CN from the "Websites" table website. We use the following SQL statement:
ExampleDELETE FROM Websites
WHERE name='Baidu' AND country='CN';
Execute the above SQL and then read the "Websites" table. The data is as follows: Delete all data
You can delete all rows in the table without deleting the table. This means that the table structure, attributes, and indexes will remain unchanged:
DELETE FROM table_name;
or
DELETE * FROM table_name;
or
DELETE * FROM table_name;
Note: Be extremely careful when deleting records! Because you can't do it again!