我正在创建测验应用程序,管理员可以定义其答案数据类型可以不同的问题!
示例:
问题ID 1:您叫什么名字? answer:约翰((varchar)] >>
问题ID 2
:您几岁? answer:25 (整数)问题ID 3
:您每小时的工资是多少? answer:30.65 (十进制)问题ID 4
:描述您自己? answer:我很好... ((文本)为了保存答案,我有2个选择:
Table profile_answers
id int [pk, increment]
question_id int
profile_id int
answer text
如您所见,我已将所有答案另存为文本!我知道它有效,但这是最好的方法吗?实际上,此应用将拥有数百万个答案,我们希望通过计算机(例如:获得客户的平均年龄,已婚客户,薪水大于30.52的客户等)分析答案,因此我想实现最佳性能!的方式
Table answers
id int [pk, increment]
question_id int
profile_id int
integer_value int
decimal_value decimal
varchar_value varchar
boolean_value boolean
longtext_value longtext
现在我可以将数据保存在适当的字段中,并将NULL放在其他字段中(答案的数据类型将在定义问题时确定)
例如:
!最好的方法是什么?question ID 1 : what is you name? answer: John (varchar) id 1 profile_question_id 1 profile_id 1 integer_value NULL decimal_value NULL varchar_value John boolean_value NULL longtext_value NULL ---------------- question ID 2 : how old are you? answer: 25 (integer) id 2 profile_question_id 2 profile_id 1 integer_value 25 decimal_value NULL varchar_value NULL boolean_value NULL longtext_value NULL ---------------- question ID 3 : how much is your salary per hour? answer: 30.65 (decimal) id 3 profile_question_id 3 profile_id 1 integer_value NULL decimal_value 30.65 varchar_value NULL boolean_value NULL longtext_value NULL
全部关于性能
我正在创建测验应用程序,管理员可以定义其答案数据类型可以不同的问题!示例:问题ID 1:您叫什么名字?答案:约翰(varchar)问题ID 2:如何...
根据有关String Type Storage Requirements的官方MySQL文档,TEXT数据类型需要L + 2个字节,其中L是字符串的长度。因此,如果给出的答案是数值100,它将使用5个字节。