Multiple foreign keys to a single column

后端 未结 7 2241
佛祖请我去吃肉
佛祖请我去吃肉 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:14

    No, you can't have a single field as a foreign key to two different tables. How would you tell where to look for the key?

    You would at least need a field that tells what kind of user it is, or two separate foreign keys.

    You could also put the information that is common for all users in one table and have separate tables for the information that is specific for the user types, so that you have a single table with user id as primary key.

提交回复
热议问题