简体   繁体   中英

User's custom profile fields

I am currently working on a system that would allow users to add additional custom fields for the contacts that they add.

I wondered what is the best and most efficient approach to add such ability?

Right now what I was thinking was to have 1 table per users (with foreign keys to a "main" contacts table) and then adding a column for each custom fields that the user adds (since I don't expect to have more then 100-200 users per database shards [sharding is easy since every users never see each-other's content in this system]), although I am not 100% sure that this would be the right solution for such problems.

也许您可以尝试使用一个单独的表来存储对用户的引用,再加上字段名称和值,这样您就可以拥有许多自定义字段。

If you go with Boyce-Codd , you separate the information and store them into a table. Means one table for all users with a foreign key.

One table per user would lead to hundreds or more tables with possible repeated information.

You need to have one table named USERS that stores the id of a user and fixed info you might want. Then, you could have a CONTACT table, that stores the type of contact user might create, and one matching table USER_CONTACT that matches the user unique id with the id of the contact that was created.

With this, you could have advanced data mining on all the information stored, like nowing how many contacts each user created, who created more, etc...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM