[英]Allow admin to create a new column?
What I'm trying to do is allow an admin to create a questionnaire. 我正在尝试做的是允许管理员创建调查表。 Every time a user writes a review for a product they must also fill out a questionnaire.
每次用户为产品撰写评论时,他们还必须填写调查表。 This is for an educational simulation.
这是用于教育模拟。
I'm currently using Visual Studio an am developing an ASP.NET MVC3 Website in C#. 我目前正在使用Visual Studio,正在用C#开发ASP.NET MVC3网站。 I also use/have SQL Server 2008 and SQL Management Studio.
我也使用/拥有SQL Server 2008和SQL Management Studio。
I'm having trouble thinking about the best way to do this. 我在考虑最好的方法时遇到了麻烦。
Right now my solution is to say "You can ask up to 10 questions" and then have a 'Questions' table in my database and store all answers with each review and have 10 'Answer' columns per review. 现在,我的解决方案是说“您最多可以提出10个问题”,然后在我的数据库中有一个“问题”表,并存储每个评论的所有答案,每个评论有10个“答案”列。
What would be even better is if I can somehow allow the admin to ask as many questions as they'd like and add more columns to my database table as needed. 更好的是,如果我能以某种方式允许管理员问他们想要的问题,并根据需要向我的数据库表中添加更多列。 Is there any way to do this?
有什么办法吗?
Or is there a better way to design my database? 还是有更好的方法来设计数据库?
Just give yourself a child table Answers
that has a foreign key to Questions
. 只需给自己一个子表
Answers
,该表具有Questions
的外键。 Then you can have as many answers as you want. 然后,您可以根据需要获得尽可能多的答案。
That isn't very normalized. 这不是很正常。
You should have a table with one record for each question/answer pair. 您应该有一张表格,其中每个问题/答案对都有一条记录。
You'll want to have a table to store the Questions
, and a separate table to store the Answers
. 您将需要一个表来存储
Questions
,以及一个单独的表来存储Answers
。 The Answers
table can then have a foreign key to the record in Questions
it's answering. 然后,
Answers
表可以在要回答的Questions
有一个外键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.