Database design for preset/custom choice questions Database design for preset/custom choice questions database database

Database design for preset/custom choice questions


Have the following tables:

Table 1:Question

  QuestionID (ID)  QuestionText (Text) 

Table 2: Question Response

  QuestionResponseId (ID)  QuestionResponseTypeId (References Question Response Type)  QuestionResponseDetailsId (References Question Response Details) - This should be used for text only values (Custom Answers)  QuestionResponse (Boolean) 

Table 3: Question Response Type

  QuestionResponseTypeId (Id)  Description (Text)  -- Dictates if the answer is a boolean or a text field

Table 4: Question Response Details

   QuestionResponseDetailsId (Id)   Description (Text) - Holds the text answer to the questions

When the following tables are populated you will have a structure that holds the question, the response of the question (text or boolean).

You could then filter on this to see only text based answers, for example:

SELECT * FROM QuestionResponseINNER JOIN QuestionResponseDetails ON QuestionResponse.QuestionResponseDetailsId = QuestionResponseDetails.QuestionResponseDetailsIdWHERE QuestionResponse.QuestionResponseTypeId = 1

Where 1 is a Text based answer and 2 is a Boolean based answer (From the Question Response Type Table)


If I were you, I would do something like this:

Table Answers:question_id INT(11)answer_id INT(11)preset_answer TINYINT(1) //1, 2, 3 for three answerscustom_answer VARCHAR(255)