XOR约束在Mysql中 [英] XOR Constraint in Mysql

查看:386
本文介绍了XOR约束在Mysql中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在mysql 5.1中实现一个 xor 外键约束



有这个表,让我们说Entity指由表ValsA和ValsB表示的两种不同类型的值集。



在Oracle中,你可以使用类似的东西。

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

但据我所知,MySQL并不真正支持CHECK约束。 >

任何想法?

解决方案

MySQL不支持检查约束。 CHECK子句被解析,但被所有存储引擎忽略。



您必须在客户端执行XOR条件。


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.

这篇关于XOR约束在Mysql中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆