开发者

Database Design Issue - Multiple "OR" Reference

I currently trying to set up an association with the following. For example, I currently have these three tables:

  • User
    • UserId
  • Company
    • CompanyId
  • Account
    • AccountId

I want the "AccountId" to reference "UserId" OR "CompanyId".

I tried:

FOREIGN KEY (AccountId) REFERENCES User (UserId),
FOREIGN KEY (AccountId) REFERENCES Comp开发者_Python百科any (CompanyId)

but this set "AccountId" to reference "UserId" AND "CompanyId".

I was wondering if anyone would have any recommendations?


Why do not you set UserId or CompanyId as per the AccountID. I mean reverse the reference order. Since each user or company will have an account so first create an account entry then just link it to the corresponding user or company entry.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜