开发者

Save multiple questions in one row

I 开发者_运维百科need to make a scheme for an database. My problem is, that I have multiple questions they belong to one exam. That means: One Exam has multiple Questions. I don't know how I can solve that. I have try to fix it with an table between "tabQuestions" and "tabTest" but I doesn't seems to be the correct approach.

I have the following tables:

tabTest: ID, Name, FK_Categorie, FK_Questions
tabQuestions: ID, Question, FK_Answer
tabAnswers: ID, Answer, FK_Solution
tabSolution: ID, Solution

Thank you very much for the help! Luca


You don't need the FK_Question field in your tabTest. What you need is a FK_Test field in your tabQuestion table where you store the id of the test the question belongs to.

...if I understood you right...?

And if I understood you right, then you should use the same for the rest of the schema too. This means you need a reference in your solutions table where you store the answer the solution belongs to etc.


You need to create two tables for this. One for exam (test) and one for questions.

The table exam (test) should have:

test_id, test_name

The table question should have:

test_id (references test_id from test table),
question_id ,
question_text.

Now you can have a 1:n relationship where one test has many questions.

But do not, I repeat: do not, store multiple questions in one row. That violates every possible good database design. Your selects, updates and inserts will be near impossible to write.

This website seems to have very good pointers for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜