Showing posts with label SQL DELETE statement. Show all posts
Showing posts with label SQL DELETE statement. Show all posts
SQL DELETE statement

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 some_column=some_value;

LampNote the WHERE clause in the SQL DELETE statement! 
The WHERE clause specifies which records or which records need to be deleted. If you omit the WHERE clause, all the records will be deleted!


Demo database

In this tutorial, we will use the RUNOOB sample database.
The following is the data selected 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 | Rookie Tutorial | http : //www.runoob.COM / | 4689 | CN | | 4 | Twitter | 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 | + ---- + ---------- ----- + --------------------------- + ------- + -------- - +COM / | 20 is | the CN | | . 5 | Facebook | HTTPS : //www.facebook.com/ |. 3 | USA | | . 6 | Baidu | HTTPS : //www.baidu.com/ |. 4 | the CN | | . 7 | Stackoverflow | http : //stackoverflow.com/ | 0 | IND | + ---- + --------------- + ------------- -------------- + ------- + --------- +COM / | 20 is | the CN | | . 5 | Facebook | HTTPS : //www.facebook.com/ |. 3 | USA | | . 6 | Baidu | HTTPS : //www.baidu.com/ |. 4 | the CN | | . 7 | Stackoverflow | http : //stackoverflow.com/ | 0 | IND | + ---- + --------------- + ------------- -------------- + ------- + --------- +Com | | 4 | CN | | 7 | stackoverflow | http : //stackoverflow.com/ | 0 | IND | + ---- + --------------- + --- ------------------------ + ------- + --------- +Com | | 4 | CN | | 7 | stackoverflow | http : //stackoverflow.com/ | 0 | IND | + ---- + --------------- + --- ------------------------ + ------- + --------- +


           
              
          
              
         
             
   


SQL DELETE instance

Suppose we want to remove the site from the "Websites" table named "Baidu" and the country for the CN site.
We use the following SQL statement:

Examples

DELETE 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 the rows in the table without deleting the table. This means that the table structure, attributes, and indexes will remain the same:
DELETE FROM table_name ;

or

DELETE * FROM table_name ;
Note: Be careful when deleting records! Because you can not come back!

Popular Posts