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
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 de actualización y ejecuta para ver los resultados.