在SQL表店的答案具有唯一的ID和存储在列的每个答案 [英] Store answers in sql table with unique id and store each answer in columns

查看:179
本文介绍了在SQL表店的答案具有唯一的ID和存储在列的每个答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在编程了一年,但我从来没有问的问题,因为现在任何地方。我有一个架构问题。我有78的问题和答案,问题是在HTML code静态和他们都可以回答的是,否,除了问题40和41我使用的是存储在表的答案N / A每个问题列。例如,
表的答案:

I've been programming for a year now but I never asked questions anywhere since now. I have a architecture issue. I have 78 questions and answers, the questions are static in the html code and all of them could be answered as yes, no, n/a except for question 40 and 41. I am storing the answers in a table using a column for each questions. For example, table answers:

userid (unique)
companyid (unique)
q1
q2
q3
...
q100

答案表只会有每家公司唯一行。如果用户编辑问卷则该行会被转移到一个历史表和一个新的行会再次插入。如果我使用一个表,问题或答案,然后对每家公司,我将有78或100行数据的答案(在这种情况下,答案是从肯定的,没有任何一个DropDownList,和N / A作为唯一的选择

The answers table will only have a unique row per company. If an user edits the questionaire then the row will be transfered to a history table and a new row will be inserted again. If I use a table for questions or answers then for each company, I will have 78 or 100 rows of data with the answer( in this case the answer will be from a dropdownlist with yes, no, and n/a as the only options.

我想知道是否有实现这一点,因为我需要实现3个不同的SQL语句(问卷完整,完全或问卷至少有一个答​​案被设置为否)或代替using语句更好的办法识别每一个问卷我要补充一个新的列,状态和工作与code后面?

I would like to know if there is a better way to implement this since i need to implement 3 different sql statements (questionaire incomplete, complete or questionaire with at least one answer being set as "No") or instead of using statement to identify each questionaire should I add a new column with status and work with the code behind?

我试图尽可能任何谏清楚将AP pretiated。

I tried to be as clear as possible and any adviced will be appretiated.

推荐答案

我preFER创建存储的用户ID,questionid和answerid表(或答案本身)。通过这种方式,你可以很容易地引入新的问题进入系统,而无需修改表结构。它也应该更容易,以确定是否有人已经回答了至少一个问题。

I prefer creating a table which stores the userid, questionid and answerid (or answer itself). This way, you can easily introduce new questions into the system without having to modify the table structure. It should also make it easier to determine if anyone has answered at least one question.

有一些潜在的缺点,只是视情况而定。

There are some potential drawbacks, just depends on the situation.

这篇关于在SQL表店的答案具有唯一的ID和存储在列的每个答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆