开发者

Relational Database (H2, Java): How do I constrain a foreign key to NOT match another foreign key in the same table?

开发者 https://www.devze.com 2022-12-23 01:37 出处:网络
Simple question.Just wondering if this can be done without me having to enforce 开发者_运维知识库this constraint manually in my Java code.These two foreign keys (together in the same table) both refer

Simple question. Just wondering if this can be done without me having to enforce 开发者_运维知识库this constraint manually in my Java code. These two foreign keys (together in the same table) both refer out to another table, but for each row, they must not be allowed to point to the same foreign item.

link text


You can use a check contraint to enforce that two columns have different values:

ALTER TABLE TableName 
    ADD CONSTRAINT ConstraintName
    CHECK fk1 <> fk2
0

精彩评论

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