SQL DELETE |
SQL Sample Code - SQL DELETE. |
The statement below deletes values in a specified row.
| DELETE FROM table_name WHERE “Condition” ; |
Always include the WHERE clause otherwise all columns will be updated
Once executed the DELETE statement action is not reversible.
If you do want to delete all rows from a table use the syntax below;
| DELETE FROM table_name;
Alternatively you can use DELETE * FROM table_name ; |
See the SQL samples section below for an explanation of the DELETE statement.
What does the SQL DELETE statement do? |
The SQL DELETE statement simply deletes the specified value(s) of a record in a table.
Sample – SQL DELETE |
In this SQL sample we will use the database table ‘tblCompany’.
| Company_ID | CompanyName | Address | Town | Sales |
| 1 | SQL Sample | 1 Sample St | Hamburg | 10000 |
| 2 | SQL Code Land | 2 Code Rd | Hamburg | 20000 |
| 3 | Sample Code World | 66 SQL St | Curry | 18000 |
| 4 | SQL Reference Ltd | 34 Reference St | Pisa | 17000 |
In the database table above we want to delete the Curry World’s record.
Use the SELECT statement below:
| DELETE FROM tblCompany WHERE CompanyName=’Curry World'; |
The table of results will look like this:
| Company_ID | CompanyName | Address | Town | Sales |
| 1 | SQL Sample | 1 Sample St | Hamburg | 10000 |
| 2 | SQL Code Land | 2 Code Rd | Hamburg | 20000 |
| 4 | SQL Reference Ltd | 34 Reference St | Pisa | 21000 |
Related SQL Sample Code:
|
|