我正在建立友谊网站。我有一个用户创建帐户时填充的问题表。
每个问题都有一个下拉菜单。
我遇到的问题是,用户无需回答问题。
强制性问题示例:
你最喜欢的颜色是什么?
非特定问题示例
你的宗教是什么?
在此方案中,哪种方法适用于存储非强制性问题。用户问题表将是巨大的,当我离开加入这三个表时,哪种方法更好地考虑性能。
方法1
对于非强制性的问题,以及用户在初次注册时未得到回答的问题,请不要这么说。
用户表
userID | username
1 | jake
用户问题表
id | userid | question
1 | 1 | 1
1 | 1 | 5
问题表
id | Question | Answer
1 | What is your favorite color | green
2 | What is your favorite color | blue
3 | What is the users religion | Christian
4 | What is the users religion | Jewish
5 | What is the users religion | Prefer not to answer
或
方法2
不要存储任何值,因为用户没有在初始注册表单上回答问题。
用户表
userID | username
1 | jake
用户问题表
id | userid | question
1 | 1 | 1
id | Question | Answer
1 | What is your favorite color | green
2 | What is your favorite color | blue
3 | What is the users religion | Christian
4 | What is the users religion | Jewish
答案 0 :(得分:1)
无论哪种方式都可以接受。无论哪种方式都有一些优点和缺点,因此它可以归结为满足您需求的内容,以及您希望用户如何与您的应用程序进行交互。以下是我能想到的问题:
Store them:
+ You know what the user saw/answered (the exact "default" value).
- Takes up extra space in the database.
- Some queries may need to filter out non-answers.
Don't store them:
+ Saves space in the database
- You can't be sure if the user was asked the question or not (particularly if questions change over time).
- Some queries are harder because of "missing" answers.
- Your code has to deliberately not store "default" (non-)answers.
总的来说,我会存储它们。