【发布时间】:2013-06-22 10:24:09
【问题描述】:
当存在primary key 和auto increments 的列时,如何在Mysql 中使用插入忽略。
我在id 上有primary keys(主键自动递增),而userId 和elmCol 是没有自动递增的主键。
所以:
id | userId | elmCol
--------------------
1 | 1 | 1 //Allow
2 | 1 | 2 //Allow
3 | 1 | 3 //Allow
4 | 1 | 1 //Not allowed if inserted again. I've put it in here just for example
5 | 2 | 1 //Allow
6 | 2 | 2 //Allow
7 | 2 | 3 //Allow
8 | 2 | 1 //Not allowed if inserted again. I've put it in here just for example
我正在使用 MySql 和 MyIsam 类型的表。我可以这样做并使用insert ignore吗?
【问题讨论】:
-
一个表中只能有一个主键,虽然它可以是字段的组合,所以你需要明确你的设置是什么。 “插入忽略”是什么意思?