Multiple foreign keys to a single column

后端 未结 7 2247
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-14 16:41

I\'m defining a database for a customer/ order system where there are two highly distinct types of customers. Because they are so different having a single customer table wo

7条回答
  •  不知归路
    2020-12-14 17:28

    Two distinct types of customer is a classic case of types and subtypes or, if you prefer, classes and subclasses. Here is an answer from another question.

    Essentially, the class-table-inheritance technique is like Arnand's answer. The use of the shared-primary-key technique is what allows you to get around the problems created by two types of foreign key in one column. The foreign key will be customer-id. That will identify one row in the customer table, and also one row in the appropriate kind of customer type table, as the case may be.

提交回复
热议问题