I have a mysql query on an InnoDB table like this:
UPDATE items SET qty = qty + 5 WHERE item_id = 1234 LIMIT 1;
Do I need to use a transaction for this? Could anything undesirable happen by not using a transaction?
I have a mysql query on an InnoDB table like this:
UPDATE items SET qty = qty + 5 WHERE item_id = 1234 LIMIT 1;
Do I need to use a transaction for this? Could anything undesirable happen by not using a transaction?
Nothing serious can happen. By default, MySQL wraps all single update/insert/delete commands in a transaction. If something goes wrong in the update, then the transaction should be rolled back correctly.
You really only need transactions when you are combining multiple changes and want them all to take effect "at the same time" or "not at all".
You can read more about this in the documentation.