mysql xor,XOR约束在Mysql中

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?

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值