Reputation:
I'm having a hard time representing the following situation in the database:
A user can declare multiple addresses (such as Home, Office, Mailing etc. as requested by client).
I have an auto-incremented primary key called UserID
that represents one user account. I've been thinking of making a BelongsToUserID
column to represent each user's form field to look like:
I can't do this because each row can only be occupied by UserID
row.
Any thoughts on how to achieve this?
Upvotes: 0
Views: 131
Reputation: 3103
you can make this in two ways
first one is simple but not adviced is that you don't make any primary key and use composite key pair as the candidate key and choose primary from that. as the table is missing the primary key its not adviced
second approach is good and i also use that is to make a master table and use that as the relation-table there and use another table to actually store the data.
in master table you can have id, userid, address_bit, and in second table you can have id, address_bit, address.
please tell me any other solution if you found one. It might help me to learn new :)
Upvotes: 0
Reputation: 6342
You want a separate table holding the addresses. Perhaps something like:
| id(primary key) | type(enum home/work/etc.) | userID | address |
Upvotes: 1