Multiple yet mutually exclusive foreign keys - is this the way to go?

前端 未结 6 848
自闭症患者
自闭症患者 2020-12-10 17:13

I have three tables: Users, Companies and Websites. Users and companies have websites, and thus each user record has a foreign key into the Websites table. Also, each compa

6条回答
  •  -上瘾入骨i
    2020-12-10 17:29

    First of all, do you really need this bi-directional link? It is a good practice to avoid it unless absolutely needed.

    I understand it that you wish to know whether the site belongs to a user or to a company. You can achieve that by having a simple boolean field in the Website table - [BelongsToUser]. If true, then you look up a user, if false - you look up a company.

提交回复
热议问题