0

I want to execute multiple inserts records and update records at once in MySQL workbench

I'm executing each one by one query it taking a very long time

UPDATE ABCD.ket SET status = '3' WHERE (id = '1'); 
UPDATE ABCD.ket SET status = '13' WHERE (id = '6'); 
UPDATE ABCD.ket SET status = '33' WHERE (id = '5'); 
UPDATE ABCD.ket SET status = '23' WHERE (id = '4');

INSERT INTO abcd.xyz (id, name, age, occp, info, status, emp, modifiedBy) VALUES ('1', 'tyu', '15', 'it', 'good', 'onwork', '101', '1');
INSERT INTO abcd.fgd (id, name, age, occp, info, status, emp, modifiedBy) VALUES ('11', 'aqwqe', '15', 'it', 'good', 'onwork', '111', '1');
INSERT INTO abcd.mvx (id, name, age, occp, info, status, emp, modifiedBy) VALUES ('122', 'poiu', '15', 'it', 'bad', 'onwork', '122', '1');
INSERT INTO abcd.lsv (id, name, age, occp, info, status, emp, modifiedBy) VALUES ('1123', 'poou', '15', 'it', 'good', 'onwork', '131', '1');
INSERT INTO abcd.efg (id, name, age, occp, info, status, emp, modifiedBy) VALUES ('1321', 'fghj', '15', 'it', 'bad', 'onwork', '144', '1');
Barmar
  • 741,623
  • 53
  • 500
  • 612
Rinkesh
  • 3
  • 2
  • Run the query as a transaction, I'd suggest with isolation level serializable. – cameronErasmus Nov 08 '22 at 16:01
  • Why do you have so many different tables with the same structure? That suggests a normalization problem. You should have a single table where `xyz`, `fgd`, etc. are column values. – Barmar Nov 08 '22 at 16:37
  • If you did that, you could insert them all in a single query with `VALUES (...), (...), (...)` – Barmar Nov 08 '22 at 16:38
  • @cameronErasmus That won't make it significantly faster. – Barmar Nov 08 '22 at 16:38
  • It's a huge query, not quite sure if it can be made faster. Many tables are being touched, that's why I suggested the isolation level @Barmar – cameronErasmus Nov 08 '22 at 16:40

0 Answers0