For example, I have three tables that store different types of users with differen开发者_如何转开发t data. But now I want to store their contact information. The table that stores their contact info would be suitable for storing data for all of the user tables.
The problem is that I have different or possibly duplicating ID's between the different user tables so it makes it impossible to create a relationship to my contact table. One solution is to create a contact table for each user type, but it seems wasteful since the only difference would be the ID.
Also, I thought of storing the contact ID in the user table but this seems less then ideal as we may not have the users contact info until later, if at all.
Any other options that I'm missing?
This is what I'd do:
table Users
UserID -PK auto number
UserLogin
UserName
table UserSpecialType1
UserSpecialType1ID -PK auto number
UserID -FK
SpecialInfoA
SpecialInfoB
table UserSpecialType2
UserSpecialType2ID -PK auto number
UserID -FK
SpecialInfoC
SpecialInfoD
table UserContactInfo
UserContactInfoID -PK auto number
UserID -FK
EmailAddress
PhoneNumber
Address
Off the top of my head, I would put all of the Users into the same table with a Type differentiator.
TABLE User
Id
Value1
Value2
UserTypeCode
TABLE UserType
TypeCode
TABLE Contact
UserId
ContactInfo
TABLE UserTypeAttribute
UserType
AttributeTypeCode
TABLE AttributeType
AttributeTypeCode
TABLE UserAttributeTypeValue
UserId
AttributeTypeCode
Value
You can use a compound key in the Contact table, e.g. UserTypeID, UserId
精彩评论