用户和联系人的数据库设计

时间:2022-01-01 12:48:34

I am writing DB schema for my application. App's users have unique phone number. Every user can have multiple contacts. I have made user_contact table to have mapping between user and contacts. contact is itself a user. Now I came to know that every contact can have multiple phone numbers. Now I am thinking how this will be managed in DB. Do I need a new table? P.S. we are using mysql database with java 8.

我正在为我的应用程序编写DB模式。 App的用户拥有唯一的电话号码。每个用户都可以有多个联系人。我已经使user_contact表具有用户和联系人之间的映射。联系本身就是一个用户。现在我开始知道每个联系人都可以拥有多个电话号码。现在我在想如何在DB中管理它。我需要一张新桌子吗?附:我们在java 8中使用mysql数据库。

1 个解决方案

#1


0  

There can be different ways. If you assume there will be limited phone numbers for each contact, you can add multiple fields one for each phone number, e.g. PhoneNo1, PhoneNo2, PhoneNo3.

可以有不同的方式。如果您认为每个联系人的电话号码有限,您可以为每个电话号码添加一个多个字段,例如PhoneNo1,PhoneNo2,PhoneNo3。

If you want to keep it flexible, you can add a table contact_phoneNos with foreign key of Contact, and keep a record for one phone number.

如果您想保持灵活性,可以添加一个表contact_phoneNos和Contact的外键,并保留一个电话号码的记录。

I suggest the first solution as its commonly implemented, like Home No. Office No, etc in each field

我建议第一个解决方案,因为它在每个领域都是常用的,如Home No. Office No等

#1


0  

There can be different ways. If you assume there will be limited phone numbers for each contact, you can add multiple fields one for each phone number, e.g. PhoneNo1, PhoneNo2, PhoneNo3.

可以有不同的方式。如果您认为每个联系人的电话号码有限,您可以为每个电话号码添加一个多个字段,例如PhoneNo1,PhoneNo2,PhoneNo3。

If you want to keep it flexible, you can add a table contact_phoneNos with foreign key of Contact, and keep a record for one phone number.

如果您想保持灵活性,可以添加一个表contact_phoneNos和Contact的外键,并保留一个电话号码的记录。

I suggest the first solution as its commonly implemented, like Home No. Office No, etc in each field

我建议第一个解决方案,因为它在每个领域都是常用的,如Home No. Office No等