我应该何时在查询中使用交易? [英] When should I use transactions in my queries?
问题描述
我正在阅读有关如何在数据库类型和数据库引擎中使用事务的非常详细的教程,但是我还没有找到可以教我何时以及为什么要使用它们的指南.
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.
这篇关于我应该何时在查询中使用交易?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!