So I want to create a test prep web app. I know there are a lot of similar ideas already in the market but I want to do it by myself.
The user will log in, choose a topic + # of questions and start a test.
So far I have:
user table
question table
category table
attempt table
Since a question will have 4 o 5 possible answers and these choices won’t be used in another question, i believe I don’t need to create a choice’s table. Am I right? So basically I need to understand if I need to create a table just for the choices or no.
There is also another features I want and I still don’t know how to design it:
Every time a user do another attempt in the same subject, random questions should be presented avoiding the ones already used in previous attempts.
User can choose if he wants to have the questions where he didn’t succeed showing up again in the next attempts.
If I understand you correct: You can do this with both one and two tables.
Using one table you have to store a “type” (1=Question and 2=Answer). Besides that you must have to store the “main” (question) id and the “sub” (answer) id in this table. In order to connect the answers to the correct question. A single table that holds connections to itself. It is possible but is more complicated.
Using two tables (question and answers) you only have to store the “main” id in the question table. It is way simpler, but basically you have 2 almost identical tables.
I don’t think there’s enough info either way, I just assumed differently! Can we get some clarification @RodMorais ? Because it affects how you structure things.
If I assume a relational dB in the form I thought it was:
Every time a user do another attempt in the same subject, random questions should be presented avoiding the ones already used in previous attempts.
User can choose if he wants to have the questions where he didn’t succeed showing up again in the next attempts.
So you can record (probably in another table, as this is a cross-cutting concern, but it could be on the user table) the IDs of the questions a user has completed successfully. So a relation mapping user to completed questions. And a relation mapping user to questions attempted unsuccessfully.
When you query the questions to show, you can do it via those relations.
Thanks all guys for replying to this. Let me share what I got so this can clarify things a bit. I still don’t know if the links/relations are ok (probably missing something).
So far, I have this:
User: store account data
Profile: store user data
Questions: store question title
Category: store category names
Answers: store answer choices
Attempt: store an user attempt, incluing category picked, questions used, wrong questions, time taken etc
History: store all attemps
User
_id:
e-mail:
hashedpw:
role:
profile: ProfileID
Also, if each question has a set of unique answers, then I would put them in the same table – they aren’t disconnected, so any benefit you would get from having them in seperate tables is lost, it just makes it much more complicated to code.