Home > Database > Mysql Tutorial > Does MySQL Overwrite Existing Values with the Same Value on Update?

Does MySQL Overwrite Existing Values with the Same Value on Update?

Barbara Streisand
Release: 2024-11-02 22:41:30
Original
526 people have browsed it

Does MySQL Overwrite Existing Values with the Same Value on Update?

Overwriting Values on MySQL Updates

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>
Copy after login

If you were to execute the following query:

<code class="sql">UPDATE `user` SET user_name = 'John' WHERE user_id = 1</code>
Copy after login

Will MySQL overwrite the existing value of 'John' with the same value, or will it ignore the update since the value remains unchanged?

Answer

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template