Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

SQL DELETE Statement

SQL DELETE Statement


The 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 condition;

Parameter Description:

| lamp | Note the WHERE clause in the SQL DELETE statement!
The WHERE clause specifies which record or records should be deleted. If you omit the WHERE clause, all records will be deleted! | | --- | --- |


Demonstration Database

In this tutorial, we will use the RUNOOB sample database.

Below is the data selected from the "Websites" table:


+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | Google       | https://www.google.cm/    | 1     | USA     |
| 2  | 淘宝       | https://www.taobao.com/   | 13    | CN      |
| 3  | Runoob Tutorial | http://www.runoob.com/    | 4689  | CN      |
| 4  | 微博       | 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" with country 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 and reading the "Websites" table again, the data looks like this:


Delete all data

You can delete all rows from a table without deleting the table itself. This means the table structure, attributes, and indexes will remain unchanged:

DELETE FROM

table_name

;

**Note:** Be extra careful when deleting records! Because you cannot undo it!