Mysql – Database structure for hierarchical quiz

database-designmongodbMySQL

I'm doing a personal project where I have a quiz with a number of boolean questions. Each question will have a two answer choices "true" and "false". Based on the selected answer, a new question will be asked with the similar pattern and based on that an another question. Any question may have any or no number of sub-questions.

The last questions in the tree (E, D) and questions with no sub-questions (F) will also store the correct answer from either "true" or "false".

The alphabets A,B,C,D,E,F are questions. A quiz can have any number of master questions (like A), sub-questions like (like B,C,D,E) and individual questions (like F).

Kindly help me design a simple database schema for for this kind of quiz. I'm open to both relational (mysql) and document (mongodb) databases.

concept diagram

Best Answer

In relational database, you should create a table called Questions which should contain following fields:

  1. ID
  2. QuestionString
  3. QuestionType (Master, Individual, sub-question)
  4. TrueCase (here you should store the ID of the next question. Since we'll store all questions in this table, therefore each questions shall have unique ID)
  5. FalseCase (ID of the question to ask if answer is not correct. If ID is null, then you should exit)

Hope it helps.