更新 MySQL 表并忽略重复条目 [英] Update MySQL table and ignore duplicate entries
问题描述
我创建了一个包含唯一mobile_no"的表
I created a table that contains a UNIQUE 'mobile_no' like
09727048248
9727048248
9824578564
9898998998
然后我要检查手机号码是否有效,如果有效则将其更改为正确的格式,例如919727048248.
Then I am going to check whether or not the mobile number is valid, and if it's valid then I want to change it into the proper format like 919727048248.
为此,我将更新查询称为..
For that I called update query like..
update bccontacts
set mobile_no='919727048248'
where mobile_no=09727048248
第一次运行成功,但是第二次就回复了
The first time it ran successfully, but the second time it replied
错误 1062 (23000):重复条目 '919727048248' 键'mobile_no'
ERROR 1062 (23000):Duplicate entry '919727048248' for key 'mobile_no'
因为已经为mobile_no"设置了唯一键.
Because there is already a unique key set for the 'mobile_no'.
那么还有其他查询会IGNORE DUPLICATE KEY ON UPDATE
吗?
So is there any other query which will IGNORE DUPLICATE KEY ON UPDATE
?
推荐答案
Use UPDATE IGNORE
:
update IGNORE bccontacts
set mobile_no='919727048248'
where mobile_no=09727048248
更多信息在这里:http://dev.mysql.com/doc/refman/5.0/en/update.html
这篇关于更新 MySQL 表并忽略重复条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!