# Method Mysql.SqlTable()->update()

Method update

  ``void` update(`mapping`(`string`:`mixed`) `record`, `void`|`int(0..2)` `clear_other_fields`)`

Description

  Updates an existing record. This requires a primary key and that `record` contains values for all primary key columns. If `record` doesn't correspond to any existing record then nothing happens.

  Updating a record normally means that all fields in `record` override those stored in the table row, while all other fields keep their values.

  It's the same for properties (i.e. fields that don't correspond to columns) which are stored in the prop_col column. If that column needs to be updated then by default the old value is fetched first, which means the update isn't atomic in that case. A property can be removed altogether by giving it the value Val.null in `record`.

  If `clear_other_fields` is 1 then all old properties are replaced by the new ones instead of merged with them, which avoids the extra fetch. If `clear_other_fields` is 2 then additionally all unmentioned columns are reset to their default values.

  For more details about the `record` mapping, see insert.

See also

  insert_or_update