开发者

Dependend Constraint in MySQL

I have not much experience with MyS开发者_如何学运维QL or SQL in general, and I don't want to dive into it too deeply. But I just wanna ask this:

I've got two columns, like this:

CREATE TABLE foo(parent INT(11) unsigned NOT NULL, ordering INT);

I just want a constraint that makes sure that if the parent key is the same, the ordering must be different. Or in maths:

For all f1,f2 in foo: parent(f1) = parent(f2) => ordering(f1) =/= ordering(f2)

How can I express that in MySQL?


I assume that =/= means "not equal" (which would be != or <> in SQL terminology).

A unique index on (parent, ordering) should do that:

CREATE UNIQUE INDEX idx_order_unique ON foo (parent, ordering);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜