对重复键忽略吗? [英] On duplicate key ignore?
本文介绍了对重复键忽略吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试完成此查询;我的标签字段设置为UNIQUE,我只是希望数据库忽略任何重复的标签.
I'm trying to finish this query; my tag field is set to UNIQUE and I simply want the database to ignore any duplicate tag.
INSERT INTO table_tags (tag) VALUES ('tag_a'),('tab_b'),('tag_c')
ON DUPLICATE KEY IGNORE '*the offending tag and carry on*'
或者甚至可以接受
INSERT INTO table_tags (tag) VALUES ('tag_a'),('tab_b'),('tag_c')
ON DUPLICATE KEY UPDATE '*the offending tag and carry on*'
推荐答案
建议不要使用INSERT IGNORE,因为它会忽略所有错误(即,草率的全局忽略).
相反,由于在您的示例中tag
是唯一键,请使用:
Would suggest NOT using INSERT IGNORE as it ignores ALL errors (ie its a sloppy global ignore).
Instead, since in your example tag
is the unique key, use:
INSERT INTO table_tags (tag) VALUES ('tag_a'),('tab_b'),('tag_c') ON DUPLICATE KEY UPDATE tag=tag;
重复键上的
产生:
on duplicate key produces:
查询正常,受影响的0行(0.07秒)
Query OK, 0 rows affected (0.07 sec)
这篇关于对重复键忽略吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文