0

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:

Desired database structure

I can't do this because each row can only be occupied by UserID row. Any thoughts on how to achieve this?

4

2 回答 2

1

您需要一个单独的表格来保存地址。也许是这样的:

| id(主键) | 类型(枚举家庭/工作/等)| 用户名 | 地址 |

于 2013-01-26T13:27:47.953 回答
0

你可以用两种方法做这个

第一个很简单,但不建议您不要创建任何主键并使用复合键对作为候选键并从中选择主键。由于该表缺少主键,因此不建议使用

第二种方法很好,我也使用它来制作一个主表并将其用作那里的关系表并使用另一个表来实际存储数据。

在主表中你可以有 id、userid、address_bit,在第二个表中你可以有 id、address_bit、地址。

如果您找到了,请告诉我任何其他解决方案。它可能会帮助我学习新知识:)

于 2013-01-26T13:36:09.783 回答