Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can I create a store procedure to insert 4 values into a table?
    primarykey
    data
    text
    <p>I'm creating a java application with components Swing but I don't how to create a stored procedure to insert 4 values into a table or if is better to use a trigger. This is my interface:</p> <pre><code>Question: ______textbox_____ correct answer:(bonne reponse ) Reponse A: _____textbox______ *A (Radio button) Reponse B: _____textbox______ *B (Radio button) [Add button] Reponse C: _____textbox______ *C (Radio button) Reponse D: _____textbox______ *D (Radio button) (levels)Paliers: _______ComboBox___ </code></pre> <p>And those are my tables in mysql</p> <pre><code>-- ----------------------------------------------------- -- Table `mydb`.`questions` -- ----------------------------------------------------- CREATE TABLE `questions` ( `idquestion` INT NOT NULL AUTO_INCREMENT , `question` VARCHAR(150) NULL , `palier_fk` INT NULL , PRIMARY KEY (`idquestion`) , INDEX `palier_fk` (`palier_fk` ASC) , CONSTRAINT `palier_fk` FOREIGN KEY (`palier_fk` ) REFERENCES `paliers` (`idpalier` ) ) -- ----------------------------------------------------- -- Table `reponses` -- ----------------------------------------------------- CREATE TABLE `reponses` ( `idreponse` INT NOT NULL AUTO_INCREMENT , `response` VARCHAR(60) NULL , `bonne` TINYINT(1) NULL , `question_fk` INT NULL , PRIMARY KEY (`idreponse`) , INDEX `question_fk` (`question_fk` ASC) , CONSTRAINT `question_fk` FOREIGN KEY (`question_fk` ) REFERENCES `questions` (`idquestion` ) ) </code></pre> <p>But the question is how can I create the stored procedure to insert 4 values and the same time to insert into the table question with the idpalier (1,2,3) </p> <p>I tried with this but it's incorrect </p> <pre><code>CREATE PROCEDURE sp_reponses_INSERT ( IN idreponse int(11), IN reponse varchar(60), IN bonne tinyint(1), IN question_fk int(11) ) BEGIN INSERT INTO reponses( reponse, bonne, question_fk ) VALUES ( reponse, bonne, question_fk ), ( reponse, bonne, question_fk ), ( reponse, bonne, question_fk ), ( reponse, bonne, question_fk ), ; END GO </code></pre> <p>By other hand I'm thinking to create a trigger instead of a stored procedure but I'm not so sure about it that. Because I have to insert the question in the table questions as well as the 4 responses in the table responses. </p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload