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

idnameage
1John25
2Anna30
3Kevin22
4Angela35
5John27
6Anna30

* Write your SQL query and execute to see results.



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