Updating Data with UPDATE


  The UPDATE statement in SQL is used to modify existing records in a table. It is essential for keeping data up-to-date.


Syntax


The basic syntax for using the UPDATE statement in SQL is:
UPDATE [table] SET [column] = [new_value] WHERE [condition];
It is important to include the WHERE clause to avoid updating all records in the table.


Purpose


The UPDATE statement is essential for:


  • Updating the price of a specific product.
  • Modifying user information in a database.
  • Updating the status of an order.


Exercises



Interactive Quiz 1: Drag and Drop

Arrastra en el orden correspondiente.


Arrastra las opciones:

UPDATE
products
SET
price
200
WHERE id = 1

Completa el código:

______
______
______
______
______
______

Interactive Quiz 2: Fill in the Blanks

ç

Rellena los huecos en cada casilla.


UPDATE  SET  =  WHERE ;

Practical Exercise:

Statement:

  Write an SQL query to update the price of a product to 75, where the product ID is 3.

Datos de Ejemplo

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

* Escribe tu consulta SQL de actualización y ejecuta para ver los resultados.



Which of the following is necessary to limit the update to specific records?