我什么时候应该使用 SQLTransaction

发布于 2024-10-07 01:52:58 字数 114 浏览 0 评论 0原文

什么时候使用 SQLTransaction 合适?

我将它们用于所有我的 INSERT、UPDATE 和 DELETE 语句。

这是正确的用法还是我做得有点过分了?

What is the appropriate time to use a SQLTransaction?

I use them for all of my INSERT, UPDATE and DELETE statements.

Is this the correct usage or am I doing a bit of overkill?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

动听の歌 2024-10-14 01:52:59

当您希望以原子方式处理一系列语句时,请使用事务 - 也就是说,它们要么全部成功并提交,要么全部回滚。

由于简单的语句已经是原子的,因此您不需要围绕每个单独的语句显式创建事务。

Use a transaction when you want a series of statements to be treated atomically - that is either they all succeed and are committed, or they are all rolled back.

Since simple statements are already atomic you don't need to explicitly create a transaction around each and every individual statement.

假情假意假温柔 2024-10-14 01:52:59

如果您的命令仅发出一次,而不是一组,那么它可能是多余的。事务用于将 sql 命令分组在一起,该组必须所有成员都成功,或者根本没有成员成功。

http://en.wikipedia.org/wiki/Atomicity_%28database_systems%29

If your commands are only single issued, and not a group, then it is probably overkill. Transactions are used to group sql commands together, a group that must have all members succeed, or none at all.

http://en.wikipedia.org/wiki/Atomicity_%28database_systems%29

爱*していゐ 2024-10-14 01:52:59

仅当您计划执行多个语句时才需要事务,并且计划在某处发生错误时回滚由语句导致的所有数据更改。不需要包装单个更新/删除语句。如果单个命令发生错误,只需在前端代码中捕获并处理错误即可。

You only need a transaction if you plan to do multiple statements, and plan to rollback all of the data changes that resulted from the statements if an error somewhere down the line occurs. Wrapping single update/delete statements is not needed. If an error occurs with a single command, simply catch and handle the error in your front-end code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文