When updating a MySQL table, it's common to wonder if the database will overwrite existing values with the same value. Consider the following table:
<code class="sql">user_id | user_name 1 John 2 Joseph 3 Juan</code>
If you were to execute the following query:
<code class="sql">UPDATE `user` SET user_name = 'John' WHERE user_id = 1</code>
Will MySQL overwrite the existing value of 'John' with the same value, or will it ignore the update since the value remains unchanged?
According to the MySQL documentation for the UPDATE statement:
If you set a column to the value it currently has, MySQL notices this and does not update it.
In our case, the user_name column for user_id 1 is already set to 'John'. Therefore, when you execute the update query, MySQL will recognize that the new value is identical to the current value and will not write any changes to the database.
The above is the detailed content of Does MySQL Overwrite Existing Values with the Same Value on Update?. For more information, please follow other related articles on the PHP Chinese website!