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

前端 未结 6 854
自闭症患者
自闭症患者 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条回答
  •  情话喂你
    2020-12-10 17:45

    Why do you need a foreign key from website to user/company at all? The principle of not duplicating data would suggest it might be better to scan the user/company tables for a matching website id. If you really need to you could always store a flag in the website table that denotes whether a given website record is for a user or a company, and then scan the appropriate table.

提交回复
热议问题