什么时候应该在查询中使用事务?

2021-12-26 00:00:00 transactions mysql pdo data-transfer

我正在阅读有关如何将事务与数据库类型和数据库引擎一起使用的非常详细的教程,但我还没有找到指导我何时以及为什么应该使用它们的指南.

I'm reading very detailed tutorials on how to use transactions with database types and database engines, but I haven't found a guide that teaches me when and why I should use them.

我知道交易通常用于银行业务,所以当我们处理货币数据时,但我可以想象它们有很多其他用途.

I know transactions are usually used for banking, so when we work with money data, but I can imagine they are used in many other ways.

今天,我正在处理一个包含用于关系数据库的各种 INSERT 语句的页面,我想知道这是否是我应该使用它们的情况之一.

Today I'm working on a page with various INSERT statements for a relational database, and I wanted to know if this is one of the cases when I should use them.

我的印象是,我不知道数据可能会部分丢失(除了编码器错误)的情况,所以我总是担心何时应该使用它们.

I get an impression that I don't know the cases when the data can be partially lost (apart from coder errors) so I'm always worried about when I should use them.

有人可以解释一下这些基本规则或提供一些链接吗?

Can someone explain or give some link with these fundamental rules?

我正在使用 MySQL 5.0.8.我应该对所有需要事务的表使用 InnoDB 吗?如果是,InnoDB 是否比常见的 MyISAM 慢,但我不应该担心?

I'm using MySQL 5.0.8. Should I use InnoDB for all tables that need transactions? If yes, is InnoDB slower than the common MyISAM but I shouldn't worry about that?

谢谢

推荐答案

基本上任何时候您的工作单元要么对外部更改敏感,要么需要能够回滚每个更改,如果发生错误或其他原因.

Basically any time you have a unit of work that is either sensitive to outside changes or needs the ability to rollback every change, if an error occurs or some other reason.

在这里寻找一些出色的答案及其使用原因.

相关文章