简体   繁体   English

多个mysql表与单个表设计

[英]multiple mysql tables vs a single table design

I'm looking into building a small survey system and i was wondering what would be the best design for the database based on: Each question can have a certain type of form for submit the answer. 我正在考虑构建一个小型调查系统,但我想知道基于以下内容的数据库最佳设计是什么:每个问题都可以具有某种类型的表单来提交答案。

  • Checkbox fields 复选框字段
  • Radio fields 无线电领域
  • input field 输入栏
  • dropdown field 下拉字段

At first i was thinking since i'm using doctrine to create an entity for each type of field and save it into a separate table. 起初,我一直在思考,因为我使用的是为每种类型的字段创建一个实体并将其保存到单独的表中的实体。 The seconds option i was thinking would be to throw all the answers i set for a question in a single table and have a type field for the question where i tell it in the form of integer what form layout should load. 我当时想的秒选项是将我为一个问题设置的所有答案都放在一个表中,并为该问题提供一个类型字段,在该字段中,我以整数形式告诉它应该加载哪种布局。

What do you think guys how should i do this ? 你们觉得我该怎么做?

You should have one table Called Questions_Answer with entities as the number of options given for the checkboxes,radioField. 您应该有一张名为Questions_Answer的表,其中实体是为复选框radioField给出的选项数量。 Like Answer 1, Answer 2 . 答案1,答案2一样 And since the number of answer can vary, u can add the columns, using the ALTER TABLE Questions_Answer ADD column_name datatype 而且由于答案的数量可能有所不同,因此您可以使用ALTER TABLE Questions_Answer ADD column_name datatype

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM