外键引用多个表 [英] Foreign key refering to multiple tables

查看:125
本文介绍了外键引用多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个表

A(ida, name)
B(ida, B-specific stuff)
C(ida, C-specific stuff)
D(ida, D-specific stuff)

,我想要另一个表E可以指B或C(不是D)。我可以在

and i want that another table E could refer to just B OR C (not D). What can i write in the

CREATE TABLE E

推荐答案

似乎我想要使用某种超类型/子类型 - 而不是简单的垂直分区。如果是这样,请介绍一个类型鉴别器。

Seems to me that you are trying to use some kind of supertype/subtype -- as opposed to simple vertical partitioning. If so, do introduce a type-discriminator.

因为这是一般的例子(A,B,C,D ..),很难猜出与什么关系,所以这里有两个选择作为我最好的猜测。

Because this is generic example (A, B, C, D ..) it is hard to guess what relates to what, so here are two options as my best guess.

选项1

选项2

这篇关于外键引用多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆