开发者

Database Design Issue - Multiple "OR" Reference

开发者 https://www.devze.com 2023-03-16 11:49 出处:网络
I currently trying to set up an association with the following. For example, I currently have these three tables:

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

精彩评论

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