0

I have a big transaction with lots of statements. Two of those statements update the same row in the Products table.

Update Products set quantity = null where id =10 
Update Products set status_id = 1 where id =10

My question is, as I'm using a transaction, will the db see these two statements as one? Is there any difference between using the above queries vs using:

Update products set quantity=null, status_id = 1 where id = 10
Fatemeh Majd
  • 699
  • 10
  • 22
  • 1
    The database will see two queries, not one and has to find the same record twice. – Shadow Aug 11 '21 at 07:30
  • 1
    Does this answer your question? [which is better one big query or multiple small query?](https://stackoverflow.com/questions/37381532/which-is-better-one-big-query-or-multiple-small-query) – Kuro Neko Aug 11 '21 at 07:38
  • not really. My question is whether it being in a transaction would change the performance and improve it – Fatemeh Majd Aug 11 '21 at 09:46
  • 1
    Putting those two statements inside `BEGIN...COMMIT` will be faster than `autocommitting` each one separately, yet slower than combining them into a single `UPDATE`. This should not be a performance issue if you are doing less than 100 such updates _per second_. – Rick James Aug 11 '21 at 16:50

0 Answers0