MySQL Question - Unique Key Not functioning correctly, or am I misunderstanding?

前端 未结 5 1657
忘掉有多难
忘掉有多难 2020-12-16 15:30

I\'m trying to create a relation where any of four different parts may be included, but any collection of the same parts should be handled as unique.

Example: An ass

5条回答
  •  时光说笑
    2020-12-16 15:47

    The only way I can think of handling this without additional triggers/programming would be to have a single "None of the Above" value in each of the referenced tables, so that your test would look like

    INSERT INTO test VALUES (1, NO_LOCATION, NO_WORKGROUP, NO_PROGRAM),
                            (1, NO_LOCATION, NO_WORKGROUP, NO_PROGRAM)
    

    Where the NO_* identifiers are the right type/length for your ID columns. This would then fail, as you'd expect it.

提交回复
热议问题