简体   繁体   English

外键目标取决于外键的值

[英]Foreign key target depends on value of foreign key

I have the basic setup depicted in this SQL Fiddle . 我有此SQL Fiddle中描述的基本设置。 In short, I have a table which has a candidate foreign key whose value may ID a record in one of several tables (if it's not NULL, that is)! 简而言之,我有一个包含候选外键的表,该外键的值可能会标识多个表之一中的一条记录(如果不是NULL的话)! How am I supposed to tell Oracle (11g r2) about this, or is putting a foreign key constraint on such a column a hopeless cause? 我应该如何告诉Oracle(11g r2)这件事,或者在这样的列上放置外键约束是没有希望的原因?

(Note: this is not due to any sort of partitioning -- the equivalents to foo , bar , and baz in the real DB have completely different schemas save for them all having IDs that can be guaranteed to not overlap.) (注意:这不是由于任何类型的分区导致的-实际数据库中的foobarbaz等效项具有完全不同的架构,但它们都具有可以保证不会重叠的ID。)

This question is very similar to Foreign Key to multiple tables 这个问题与多个表的外键非常相似

That question's top answer proposes many good solutions, but in your case a standard practice you could follow is to have a column for the ids to each of your tables(bar_id, baz_id, and foo_id). 该问题的最高答案提出了许多好的解决方案,但是对于您而言,您可以遵循的标准做法是为每个表(bar_id,baz_id和foo_id)的ID设置一列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM