Updating data with DELETE
The DELETE command in SQL allows you to remove records from a table. It is essential to use it with caution to avoid the loss of important data.
Syntax
The basic syntax for using DELETE in SQL is:DELETE FROM [table] WHERE [condition];
Make sure to specify the condition to avoid deleting all the records from the table.
Purpose
The purpose of the DELETE command is to remove specific records from a table. For example, it allows you to:
- Delete products with a price less than 50.
- Delete users who have not accessed the platform in the last year.
- Delete records of canceled orders.
Exercises
Interactive Test 1: Drag and Drop
Drag in the corresponding order.
Drag the options:
DELETE
FROM
WHERE
Completa el código:
______
______
______
Interactive Test 2: Fill in the Blanks
Fill the Blanks.
DELETE FROM products WHERE price ;
Practical Exercise:
Statement:
Write an SQL query to delete all products with a price less than 30.
Example Data
| id | name | age |
|---|---|---|
| 1 | John | 25 |
| 2 | Anna | 30 |
| 3 | Kevin | 22 |
| 4 | Angela | 35 |
| 5 | John | 27 |
| 6 | Anna | 30 |
* Write your SQL query and execute to see results.