SQL UPDATE

UPDATE statement is used to modify values in a table.

SQL UPDATE syntax is :

UPDATE tablename SET columna1 = valor1, columna2 = valor2 WHERE columna3 = valor3

SET clause sets new values for the columns indicated.

WHERE clause used to select the rows you want to modify.

Eye: If you omit the WHERE clause, by default, modify the values in all rows of the table.

Example of using SQL UPDATE

namesurnamenickname
HARRYCLARKWHITE
WILLIAMJONESCLARK
HARRYSMITHBENITO
JOHNBROWNANDERSON

If we change the nickname 'BENITO' by 'JOHNSON' execute:

UPDATE people SET nickname = 'JOHNSON' WHERE name = 'HARRY' AND surname = 'SMITH' AND nickname = 'BENITO'

Now the table 'people' will look like this:

namesurnamenickname
HARRYCLARKWHITE
WILLIAMJONESCLARK
HARRYSMITHJOHNSON
JOHNBROWNANDERSON