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
Arrastra en el orden correspondiente.
Arrastra las opciones:
DELETE
FROM
WHERE
Completa el código:
______
______
______
Interactive Test 2: Fill in the Blanks
Rellena los huecos en cada casilla.
DELETE FROM products WHERE price ;
Practical Exercise:
Statement:
Write an SQL query to delete all products with a price less than 30.
Datos de Ejemplo
id | name | age |
---|---|---|
1 | Juan | 25 |
2 | Ana | 30 |
3 | Luis | 22 |
4 | Marta | 35 |
5 | Juan | 27 |
6 | Ana | 30 |
* Escribe tu consulta SQL y ejecuta para ver los resultados.