SQL insert into multiple rows and parameters

asked 2019-02-14 20:16:36 +0200

fifou64 gravatar image

Hi, I want to insert several records which are redundant in my libre office database.

I have two tables : table1 and table2 which are connected by a 1 to many relationship. Basically I must insert one record in table1 and then some other records in table2

I went to tools--->SQL And then I typed : INSERT INTO "table1" ("whatever", "field") VALUES (2,'some text'); This worked like a charm.

Then I tried to insert multiple rows to table2: INSERT INTO "table2" ("idEcriture", "idCompte","credit","idLocataire","idBien") VALUES (415,706000,450,1,1), (415,708000,80,1,1), (415,626100,15,1,1), (415,606130,28,1,1), (415,606110,27,1,1); Here 415 is the coresponding key in table 1. So I had to check first that it was 415. Not very handy.

I get the error :

1: Unexpected token: , in statement [,]

So here are several questions : - How can I insert multiple rows? What am I doing wrong? - Can I use parameters in my request : I will have to do this operation several times (like 12 times) I want something like : declare @idEcriture int set @idEcriture = 415; INSERT INTO "table2" ("idEcriture", "idCompte","credit","idLocataire","idBien") VALUES (@idEcriture,706000,450,1,1), `

Is there a way for me to I enter the whole thing in one operation? Like (one record in table1 and then the 5 corresponding records in table2) and this 12 times. I am thinking af a loop.

I hope I made myself clear.

edit retag flag offensive close merge delete