单个更新查询所需的事务?

时间:2022-11-28 01:32:08

I have a mysql query on an InnoDB table like this:

我在InnoDB表上有一个mysql查询,如下所示:

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?

我需要使用交易吗?不使用交易可能会发生什么不良事件吗?

1 个解决方案

#1


9  

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.

没有什么可以发生的。默认情况下,MySQL在事务中包装所有单个update / insert / delete命令。如果更新中出现问题,则应正确回滚事务。

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.

您可以在文档中阅读更多相关信息。

#1


9  

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.

没有什么可以发生的。默认情况下,MySQL在事务中包装所有单个update / insert / delete命令。如果更新中出现问题,则应正确回滚事务。

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.

您可以在文档中阅读更多相关信息。