Updating rows · Actualización de filas
Changing rows with UPDATE
UPDATE changes values in the rows that match a WHERE condition:
SET lists the columns to change. You can change several at once, separated by commas: SET price = 0.95, in_stock = 150.
Modificar filas con UPDATE
UPDATE cambia valores en las filas que coinciden con una condición WHERE:
UPDATE product SET price = 0.95 WHERE code = 'P02';
SET enumera las columnas para cambiar. Puedes modificar varias a la vez, separadas por comas: SET price = 0.95, in_stock = 150.
Always use WHERE
The WHERE decides which rows change. Leave it out and every row is updated:
So nearly every UPDATE should have a WHERE. The checker runs your UPDATE, then reads the table back to confirm only the right row changed.
Usar siempre WHERE
El WHERE decide cuáles filas cambian. Si lo omites, se actualizarán todas las filas:
UPDATE product SET price = 0; -- changes ALL products!
Por eso casi todo UPDATE debería tener un WHERE. El verificador ejecuta tu UPDATE, luego lee la tabla nuevamente para confirmar que solo cambió la fila correcta.
Common mistakes
UPDATEwithout aWHEREchanges every row — always add theWHERE.- Set several columns at once with commas.
Errores comunes
UPDATEsin unWHEREcambia todas las filas — siempre agrega elWHERE.- Establece varias columnas a la vez usando comas.
Change the price of the product with code 'P02' to · hasta 0.95. Be sure to use a WHERE so only that product changes. · Cambia el precio del producto con código 'P02' a 0.95. Asegúrate de usar un WHERE para que solo cambie ese producto.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
A delivery arrived, so every product gains 10 in stock. Update with an expression — SET in_stock = in_stock + 10 — and no WHERE, so it applies to all rows. · Llegó una entrega, así que todos los productos ganan 10 en stock. Actualiza con una expresión — SET in_stock = in_stock + 10 — y sin WHERE, para que se aplique a todas las filas.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.