Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does MySQL overwrite a column of same value on update?

Tags:

When updating a table in MySQL, for example:

Table user

user_id | user_name  1         John 2         Joseph 3         Juan 

If I run the query

UPDATE `user` SET user_name = 'John' WHERE user_id = 1 

Will MySQL write the same value again or ignore it since it's the same content?

like image 311
Phiter Avatar asked Feb 12 '16 13:02

Phiter


People also ask

Does UPDATE in SQL overwrite?

If you tell SQL Server to UPDATE some rows - it will update those rows. SQL Server doesn't do any "matching" of its own. That's up to you - you control the WHERE clause for the UPDATE .

How UPDATE same column with different values in MySQL?

MySQL UPDATE multiple columnsMySQL UPDATE command can be used to update multiple columns by specifying a comma separated list of column_name = new_value. Where column_name is the name of the column to be updated and new_value is the new value with which the column will be updated.

How does UPDATE work in MySQL?

For the single-table syntax, the UPDATE statement updates columns of existing rows in the named table with new values. The SET clause indicates which columns to modify and the values they should be given. Each value can be given as an expression, or the keyword DEFAULT to set a column explicitly to its default value.

How UPDATE multiple columns with same value in SQL?

We can update multiple columns by specifying multiple columns after the SET command in the UPDATE statement. The UPDATE statement is always followed by the SET command, it specifies the column where the update is required.


1 Answers

As the MySQL manual for the UPDATE statement implies,

If you set a column to the value it currently has, MySQL notices this and does not update it.

So, if you run this query, MySQL will understand that the value you're trying to apply is the same as the current one for the specified column, and it won't write anything to the database.

like image 140
Phiter Avatar answered Oct 27 '22 01:10

Phiter