避免在MySQL中插入重复的行 [英] Avoiding inserting duplicate rows in mySQL
本文介绍了避免在MySQL中插入重复的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有auto_inc
id(主键)的表.
我试图避免插入重复的行.
I have a table with an auto_inc
id (primary key).
I am trying to avoid the insertion of duplicate rows.
重复行的示例:
id | field a | field b | field c |
1 4 6 7
2 4 6 7
键(id
)不是重复的,因为它是由MySQL自动生成的,但是所有其他字段都是相同的.
The key (id
) is not duplicate since it is automatically generated by MySQL, but all other fields are identical.
推荐答案
在字段a,b,c上创建唯一索引.
Make a unique index on fields a,b,c.
ALTER TABLE `table` ADD UNIQUE (
`a` ,
`b` ,
`c`
);
这篇关于避免在MySQL中插入重复的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文