开发者

Need Help with Preference table database design

I'm currently developing a web application using MYSQL database InnoDB format and need some help with my preference database desgin.

Basically I need to have a preference table to determine the user car brand preference.

BMW 0 or 1 TOYOTA 0 or 1 HONDA 0 or 1 MERCEDES 0 or 1 HOLDEN 0 or 1 FORD 0 or 1 (0 means dislike and 1 means like)

I used to store all the responses in one table but is hard to maintain when I add new car brand . So I need to make it dynamic so I don't have to modify the database column when i add more car brands.

So Each User in my system have their own user's car preference profile.

So my new design its to have a user table, preference table and a UserPreference table

UserPreference table

providerId
preferenceId
response

My Question is How can I populate the User preference profile rows in the database (default all to 0) once a new user sign up ?

Or should I make my UserPreference table like below so I don't have to populate the user preference profile rows? And only create a row in the User Preference table when a user like a car brand.

Which is a better approach?

Us开发者_开发知识库erPreference table

    providerId
    preferenceId

Thanks so much in advance!


I think the second approach is the best option, Only add the preferences that people have explicitly chosen. That way you can assume when working with the data that everything is 0 unless a preference exists in the table to show otherwise.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜