XOR Constraint in Mysql

纵饮孤独 提交于 2019-12-12 17:05:12

问题


I want to implement a kind of xor constraint on foreign keys in mysql 5.1

There is this table, let's say Entity which can refer to two different kinds of valuesets represented by Tables ValsA and ValsB. Now I would like to implement a constraint wich makes sure that exactly one of those two is mapped, and the other one isn't.

In Oracle you could use something like

CHECK (NVL2(FK_A,1,0)+NVL2(FK_B,1,0)=1));

but as far as I understand it MySQL does not really support CHECK Constraints (yet).

Any ideas?


回答1:


Correct. MySQL does not support check contraints. The CHECK clause is parsed but ignored by all storage engines.

You'd have to enforce the XOR condition on the client side.



来源:https://stackoverflow.com/questions/3812468/xor-constraint-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!