简体   繁体   中英

Database structure for quiz hierarchical data?

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.

概念图

How about (assuming relational) questions, answers and a link from answers to the following question.

Questions
---------
Question_Id
Question details

Answers
-------
Question_Id
Correct FLAG
Next_Question (fk to Question_Id)

when next question is null you can assume the quiz is over.

I don't think noSql will naturally lend itself to this sort of problem. I'd stick with relational unless you have a specific need for nosql or you could consider using a graph database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM