MySQL:设计用户的帐户设置表

时间:2011-11-26 07:37:02

标签: mysql database-design

用户的帐户设置可能会非常冗长,具体取决于您希望获得的详细信息(例如,接收新闻稿TINYINT(1),允许搜索TINYINT(1)等)。我想知道最好的方法是什么,因为现在所有这些设置都放在我的用户表中,该表已经有大约30列,可能很快就会增长。

1 个答案:

答案 0 :(得分:0)

您可以考虑使用set数据类型: - http://dev.mysql.com/doc/refman/5.0/en/set.html

profile set ('newsletter', 'searchable', ....)

进行查询时,它将是: -

select ... from user
where find_in_set('searchable', profile)>0 and ...

或者,您可以创建配置文件表以将每个配置文件规范化为一个记录

user ( id, ...);
user_profile (user_id, profile_id, profile_value);
profile (id, name);

搜索: -

select ... from user
inner join user_profile on user.id=user_profile.user_id
inner join profile on profile.id=user_profile.profile_id
where profile.name='searchable' and user_profile.profile_value=1 ...