Forum Moderators: open
I have a look-up form with 10 fields. The user can edit any of the 10 fields. The user decides to only edit 1 field and the form is submitted.
The query in PHP is something like
UPDATE table SET field1 = '$field1', field2 = 'field2', etc
Does MySQL update all the fields even if the data is exactly the same? Or does MySQL skip the update on the field if the data is the same?
So, MySQL would only actually update the one field that was changed and not spend the resources updating the ones that are the same.
I thought I had read that MySQL only updates what has changed.
Thanks,
John
If you haven't changed field 2 then instead of:
UPDATE table SET field1 = '$field1', field2 = 'field2', etc
Write:
UPDATE table SET field1 = '$field1', etc
The unreferenced fields will be fully ignored.
and not spend the resources updating the ones that are the same.
If I tell you:
a = 7, and then
b = 10, then finally
a = 3
Would you bother checking to see if a is already 3 before setting it to 3?