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.
假设table A可以属于table B或table C,但不能同时属于两者。
table A
table B
table C
似乎可以在 SQL Server 中为这种情况使用外键约束。
Elixir 的 Ecto 库如何表示这种关系?
您可以将其构造为对每个外键约束使用单独的列,然后保证只填充一个:
create table A ( . . . b_id int, c_id int, foreign key (b_id) references b(b_id), foreign key (c_id) references c(c_id), check (b_id is null or c_id is null) )