What is the best way to create this database?

what's the best way to create a question and answer database Script

the user can ask a question with a set of options, among which there is a correct answer

the database should save the question, all options and the correct answer.

the best way that comes to my mind is to make 2 tables:

Question table:

  • ID
  • Question
  • Right_Answer_ID

Selection table:

  • ID
  • The choice
  • Question_ID

I use PHP and MYSQL for this, so if I use this method, it will be a little difficult to insert information into my database, because I need to insert a question and paste all the options and select the correct one. Right_Answer_ID for this identifier is a long process, and I'm sure there is a better way to achieve this, please HELP.

thank

+3
6

?

  • ID

  • ID
  • Question_ID
  • Is_Right_Answer
+4

22 ...

First edition book cover

, :
- , , SQL.

, , , , , , .
, , " " "Right_Answer_ID" "" "IsCorrect" "", INSERT, model: , (, , "IsCorrect" , "" )

+1

, - . . .

0

- , , , , , . , , mjv .

, "" "" , question_id , .

0

, , - . , , id, question, choice1, choice2, ...., choicen, correct_choice .

0

, . , :

:

* ID
* Question
* Right_Answer_Index

:

* Index
* Question_ID
* Choice

If you need a primary key in the selection table, you can combine Index with Question_ID. Thus, in the html form that you use to create new questions and answers, you can have additional input to indicate the index number of the right choice, and thus, when you insert your question, you have all the necessary information (before The correct selection entry has been added).

0
source

Source: https://habr.com/ru/post/1730532/


All Articles