简体   繁体   中英

database design for user profiles

User can create one of two profile types, for example freelancer and company. This profile types have several common and several unique fields. Company may have many users as workers.

To be more clear: user HAS_ONE profile (freelancer or company); company HAS_MANY user;

Any suggestions about best database design for this situation?

One database table with a foreign key to the profile type ProfileTypeID values which may include but is not limited to the following:

  • freelancer
  • company

This one field will help you determine what additional attributes are associated to the user. The rest is all simple UI.

It's Inheritance. When you face this case you have 3 options.

First option is one big table for company and freelancer with a typeid table to know if it's a company or freelancer, but in your case you would end up with a lot of nulls .

Second option would be 2 separate tables for company and freelancer and the common attributes in your user table. Then you have to add typeId in your user table to know if it's a company or freelancer

third option would be to make 1 big table for user, freelancer and company but this would be the option with the most nulls.

The best option in your case would be the second option because you have several common and several unique fields.

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