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.
精彩评论