Values are assigned to the named columns. Unmentioned columns remain unchanged. The search_condition acts in the same way as in the SELECT command. It restricts the coverage of the command to those rows that satisfy the specified criteria. If the WHERE keyword and the search_condition are omitted, all rows of the table are affected. It is possible to specify search_conditions which hit no rows. In this case no rows are updated - and no error or exception occurs.

As shown previously in the introductory page, the UPDATE command is very flexible. Within one command we can choose an arbitrary combination of the two features:

change one or more columns

change zero, one or more rows - depending on the search_condition.

Additionally, values can have a dynamic nature like system date, timestamp or timezone - depending on your implementation.

Change column remark of row Fishing in table hobby to: 'Catching fishes with or without tools.'.

Click to see solution

-- Change one column of one rowUPDATEhobbySETremark='Catching fishes with or without tools.'WHEREhobbyname='Fishing';-- or: WHERE id = 2;COMMIT;-- Check the resultSELECT*FROMhobby;

Change column remark of all rows in table hobby to: 'A creative leisure activity.'. Check the success of the command without COMMIT-ting. Revert the changes.

Click to see solution

-- no WHERE clause ==> all rows affectedUPDATEhobbySETremark='A creative leisure activity.';-- Check the resultSELECT*FROMhobby;-- We don't what to save this values. So we revert the changes.ROLLBACK;

Find a solution for the previous exercise, which uses a WHERE clause.

Click to see solution

-- A WHERE clauses, which hits all rowsUPDATEhobbySETremark='A creative leisure activity.'WHEREid>=1;-- Check the resultSELECT*FROMhobby;-- We don't what to save this values. So we revert the changes.ROLLBACK;