J
J
joha07382021-08-01 15:28:41
MySQL
joha0738, 2021-08-01 15:28:41

How to implement the creation of an online questionnaire with questions and answers?

I need to create a site where an authorized user with the role of ADMIN can create different questionnaires in which the number of questions and the number of answer options can be different. I don't understand how to implement this for some reason.
1: I can create a regular table in the database, where there are already certain columns and I don’t know how to expand it if necessary.
2: For the questionnaire it is necessary to create several tables (For the name of the questionnaire, the name of its questions and answer options) or is it better to cram all this into one table?
I am using (Spring MVC,security,java,mysql,maven)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Slava Rozhnev, 2021-08-01
@joha0738

1. A properly designed database will need to be changed only when the application logic changes
2. An example of the table structure for your description:

create table questionnaires (
        id int primary key auto_increment,
  	title varchar(255)
);

create table questios (
        id int primary key auto_increment,
  	questionnaire_id int,
  	title varchar(255),
  	foreign key (questionnaire_id) references questionnaires(id)
);

create table answers (
        id int primary key auto_increment,
  	question_id int,
  	title varchar(255),
  	rigth bool,
  	foreign key (question_id) references questios(id)
);

SQL online fiddle

D
Developer, 2021-08-01
@samodum

There is only one piece of advice here - get a job to gain experience

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question