Updating rows · Atualizando linhas
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.
Alterando linhas com UPDATE
UPDATE altera valores nas linhas que correspondem a uma condição de WHERE:
UPDATE product SET price = 0.95 WHERE code = 'P02';
SET lista as colunas a alterar. Você pode alterar várias de uma vez, separadas por vírgulas: 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.
Sempre use WHERE
O WHERE decide quais linhas são alteradas. Se omitido, todas as linhas são atualizadas:
UPDATE product SET price = 0; -- changes ALL products!
Por isso, quase todo UPDATE deve ter um WHERE. O verificador executa seu UPDATE, depois lê a tabela de volta para confirmar que apenas a linha certa foi alterada.
Common mistakes
UPDATEwithout aWHEREchanges every row — always add theWHERE.- Set several columns at once with commas.
Erros comuns
UPDATEsem umWHEREaltera todas as linhas — sempre adicione oWHERE.- Defina várias colunas de uma vez com vírgulas.
Change the price of the product with code 'P02' to · até 0.95. Be sure to use a WHERE so only that product changes. · Altere o preço do produto com código 'P02' para 0.95. Certifique-se de usar um WHERE para que apenas aquele produto mude.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
A delivery arrived, so every product gains 10 in stock. Update with an expression — SET in_stock = in_stock + 10 — and no · nenhuma WHERE, so it applies to all rows. · Uma entrega chegou, então todo produto ganha 10 no estoque. Atualize com uma expressão — SET in_stock = in_stock + 10 — e sem WHERE, para que se aplique a todas as linhas.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.