How does one create a data base for a survey/questionnaire? [duplicate]

Posted on

Question :

I need to create a database for a wordy questionnaire. At the end I want to be able to graph my information. Where can I do this?

Answer :

Create a table that stores the questions, answer type and answer values

+-------------------------------------------------------------------------+
| Questions                                                               |
+---------------+-----------------+------+-----+---------+----------------+
| Field         | Type            | Null | Key | Default | Extra          |
+---------------+-----------------+------+-----+---------+----------------+
| QuestionId    | int(6) unsigned | NO   | PRI | NULL    | auto_increment |
| QuestionText  | varchar(256)    | YES  |     | NULL    |                |
| AnswerOptions | varchar(512)    | YES  |     |         |                |
+---------------+-----------------+------+-----+---------+----------------+

Comments

  • AnswerOptions field is optional, and its default is set to an empty string. I would set it to a JSON string vector containing the options for a question with DataType set to checklist, or list. (Something like [ "first option", "second option" ])

Create a table that stores the answers

+---------------------------------------------------------------------------------+
| Answers                                                                         |
+------------+------------------+------+-----+-------------------+----------------+
| Field      | Type             | Null | Key | Default           | Extra          |
+------------+------------------+------+-----+-------------------+----------------+
| AnswerId   | int(10) unsigned | NO   | PRI | NULL              | auto_increment |
| AnswerTime | datetime         | YES  |     | CURRENT_TIMESTAMP |                |
| Username   | varchar(20)      | NO   |     | NULL              |                |
| Answers    | int(6)           | NO   |     | NULL              |                |
+------------+------------------+------+-----+-------------------+----------------+

Comments

  • I suppose you can keep track of people who answer your poll, so I added a username field. If that’s not possible, you can simply not add that field to your table.
  • The Answers field should store JSON as well, because that will ensure maximum flexibility: you can add as many questions as you want, and as many answers as you want. So, JSON which can keep an object with key-pair items, representing the question index (the QuestionId field from Questions table) and the answer index (the index of the answer in the vector from AnswerOptions field).

I think I’ve covered everything you need. The rest of your question represents programming, so I don’t think it belongs here. You can find information about graphing database information on Google

Leave a Reply

Your email address will not be published. Required fields are marked *