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

idnameage
1Juan25
2Ana30
3Luis22
4Marta35
5Juan27
6Ana30

* Escribe tu consulta SQL y ejecuta para ver los resultados.



Which of the following is a command to delete data in SQL?