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.
在这里寻找一些出色的答案及其使用原因.
这篇关于什么时候应该在查询中使用事务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么时候应该在查询中使用事务?
基础教程推荐
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 无法解决整理冲突 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
