Answer the question
In order to leave comments, you need to log in
How to properly organize changes of 50-100 rows in mysql?
The site has a product catalog, you need to make it possible to tick 50-100 positions and change a certain characteristic of them. How can I check it in the database? Do 50-100 requests in a cycle? How right?
Answer the question
In order to leave comments, you need to log in
Do 50-100 requests in a cycle?
UPDATE table_items
SET option = true
WHERE id in (11, 45, 81);
If the change is the same and the structure of the database allows - a query like:
If the changes are different and lines 50-100 - then separate queries.
If there are 100k+ rows, you can do perversions with an intermediate table - put data into it for updating, then do update with join.
If you need to do something the same for everyone - i.e. for all, set the value of one field to be the same - then update with where id in ....
otherwise - for each change a separate request;
If the database driver allows you to make several queries at the same time:
mysql.query('UPDATE ... WHERE ID = 1; UPDATE ... WHERE ID = 2;....'. ....)
UPDATE "my-table" AS t
SET "val"=v."val",
"msg"=v."msg"
FROM (VALUES(1,123,'hello'),(2,456,'world!'))
AS v("id","val","msg") WHERE v.id = t.id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question