MYSQL是否会在更新时覆盖相同值的列? [英] Does MYSQL overwrite a column of same value on update?

查看:170
本文介绍了MYSQL是否会在更新时覆盖相同值的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在mysql中更新表时:

When updating a table in mysql, for example:

表格 user

user_id | user_name

1         John
2         Joseph
3         Juan

如果我运行查询

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

MYSQL将再次写入相同的值,还是因为内容相同而忽略它?

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

这是我提出的一个问题,正如 Stack Overflow鼓励一样,我认为这会有所帮助有同样问题的其他程序员的未来.

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.

推荐答案

作为

如果将列设置为其当前值,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是否会在更新时覆盖相同值的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆