When updating a table in mysql, for example:
在mysql中更新表时,例如:
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?
MYSQL会再次写入相同的值还是忽略它,因为它的内容相同?
This is a Q&A question I made, as Stack Overflow encourages it, I think it will be helpful in the future for the fellow programmers with the same question.
这是我提出的一个问答问题,因为Stack Overflow鼓励了这个问题,我认为这个问题对将来遇到同样问题的程序员很有帮助。
1 个解决方案
#1
13
As the MYSQL Manual for the UPDATE statement implies,
如更新语句的MYSQL手册所示,
If you set a column to the value it currently has, MySQL notices this and does not update it.
如果将列设置为当前的值,MySQL会注意到这一点,不会更新它。
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.
因此,如果运行此查询,MYSQL将理解您试图应用的值与指定列的当前值相同,它不会向数据库写入任何内容。
#1
13
As the MYSQL Manual for the UPDATE statement implies,
如更新语句的MYSQL手册所示,
If you set a column to the value it currently has, MySQL notices this and does not update it.
如果将列设置为当前的值,MySQL会注意到这一点,不会更新它。
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.
因此,如果运行此查询,MYSQL将理解您试图应用的值与指定列的当前值相同,它不会向数据库写入任何内容。