【发布时间】:2015-04-23 04:43:45
【问题描述】:
假设我在一个 mysql 表中有 三个 字段。
- 字段1
- 字段2
- 字段3
我知道,如果我将 field1 和 field2 加入为唯一字段,则适用以下规则:
field1, field2
1 2 //is allowed
2 1 //is NOT allowed if (1,2) exists
我怀疑这将如何处理三个字段。例如
field1, field2, field3
1 2 1 //is allowed
1 2 2 //is this allowed (if previous exist)?
2 1 2 //is this allowed? (if previous exist)
2 1 3 //is this allowed? (only if the first one exists)
我真正需要的是避免重复 field1 和 field2 对。也就是说,我希望 1 2 1 和 1 2 2 一样存在,但 2 1 1 或 2 1 2 不应该存在(注意 field1 和 field2 开关)。这究竟是如何工作的?
【问题讨论】:
-
一个想法是考虑相反的逻辑:始终存储两个版本,但带有指示哪个版本是“真实”的标志
标签: mysql