Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
简单的问题。只是想知道这是否可以在我不必在我的 Java 代码中手动强制执行此约束的情况下完成。这两个外键(一起在同一个表中)都指向另一个表,但是对于每一行,它们不能指向同一个外项。
链接文本
您可以使用检查约束来强制两列具有不同的值:
ALTER TABLE TableName ADD CONSTRAINT ConstraintName CHECK fk1 <> fk2