WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL DELETE Statement



DELETE statement is used to delete records in a table.


SQL DELETE statement

DELETE statement is used to delete rows in a table.

SQL DELETE syntax

DELETE FROM table_name
WHERE some_column=some_value;

lamp Note the WHERE clause in the SQL DELETE statement!
The WHERE clause specifies which records 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 welookups sample database.

Here is the data from the "Websites" table:

+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | Google       | https://www.google.com/ | 1     | USA     |
| 2  | Indiatimes          | https://www.Indiatimes.com/| 13    | IN      |
| 3  | zomato      | http://www.zomato.com/ | 5000  | CN      |
| 4  | indiamart          | http://indiamart.com/      | 20    | IN      |
| 5  | Facebook     | https://www.facebook.com/| 3     | USA     |
|  6 | godaddy         | https://www.godaddy.com/ |     4 | IN      |
|  7 | stackoverflow | http://stackoverflow.com/|     0 | IND     |
+----+---------------+---------------------------+-------+---------+


SQL DELETE instance

Suppose we want to delete from the "Websites" table a website with the website name "Baidu" and the country CN.

We use the following SQL statement:

Example

DELETE FROM Websites WHERE name='welookups' 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 a 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 ;

Note: Be careful when deleting records! Because you can't come back!