Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Designing databse for questions and answers where some answers are text and some are multiple choice [closed]

I know there are a few related posts but I didn't fully understand what to do.

I have a general idea of how to go about this. I am not too far into database design unfortunately so I require help.

Have table with questions_id, have table for possible_answer_id for each question_id.

Then have a linking table question_answers with user_id, question_id, answer_id, timestamp to register submitted forms.

But my problem is that some questions are answered with just a string so I am having trouble conceptualizing what to do about it.

e,g 
for some I need: question_id string_answer (any answer is allowed)
for others:      question_id answer_id     (out of set of allowed answers)
and perhaps:     question_id bool_answer   (true/false)

Do I add question_type somewhere so I have two different tables for this?

If the question is not clear, please let me know.

like image 751
Eugene Avatar asked Feb 24 '12 15:02

Eugene


1 Answers

Edited to take into account Eugene's questions.

Here are the tables that your system will need, and an explanation of each table.

1. Person

This table will contain all of the information about the person taking a test. The key to the table is a person id, which is an integer that automatically increments for each person row added to the table. Most current databases have an identity integer or auto-incrementing integer, which is normally the primary key of the table.

2. Question

This table contains all of the questions that you've ever thought of asking.

The question table would contain a flag (integer or character) that would indicate the type of question, as you've outlined.

  • Any string answer
  • Set of allotted answers
  • True / false

3. Answer

This table contains the sets of answers for the questions in the Question table that require a set of allotted answers. The group key to the set of answers is the primary key of the question.

Programatically, you would select a row from the question table. Only if the flag is set of allotted answers would you then browse the answer table in a separate SQL query.

4. Test

This table contains the date and time the test was created.

5. Test Question

This table contains the questions selected from the Question table for one particular test. The group key for the set of test questions is the Test table id.

The reason for having a Test Question table is questions and answers can be added, changed, or removed from the Question and Answer table. The Test Questions table is a historical table in that once the rows are added, they are never changed or removed.

6. Test Taken

This table contains the Person id of the person that took the test, the Test id of the Test, and the date and time the test was taken.

7. Test Answer

This table contains the answers to the test. The group key to the set of Test Answers is the Test Taken id and the Test Question id.

like image 105
Gilbert Le Blanc Avatar answered Sep 30 '22 15:09

Gilbert Le Blanc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!