sql server 事务_SQL Server事务概述

sql server 事务

In general, a Transaction is a single unit of work consists of multiple related tasks that should succeed or fail as one atomic unit. To make the concept of the transaction more familiar and why it should go all or none, imagine one of the most critical transaction examples in our daily life, which is withdrawing money from the ATM.

通常, 事务是一个工作单元,由多个相关任务组成,这些任务应该作为一个原子单元成功或失败。 为了使交易的概念更加熟悉,以及为什么不进行全部交易或不进行交易,请想象一下我们日常生活中最关键的交易示例之一,即从ATM取款。

After a hard-working month, you are happy that your salary is released. As it is late to visit the bank after the working hours, your destination now is the ATM. All of us are familiar with the steps of withdrawing money from the ATM, but it deserves listing the common ones below:

经过一个月的努力工作,您很高兴自己的工资被释放了。 由于下班后去银行晚了,所以现在您的目的地是ATM。 我们所有人都熟悉从ATM取款的步骤,但是值得在下面列出以下常见的步骤:

  1. Insert your card

    插入您的卡
  2. Select the language

    选择语言
  3. Enter your PIN

    输入密码
  4. Select the transaction type, which is withdraw in our example here

    选择交易类型,在我们的示例中将其提取
  5. Enter the amount

    输入金额
  6. Pull the card

    拉卡
  7. Take your money

    拿你的钱

The previous tasks should run as one unit to keep your bank account in consistent state. This means that, if you specify the amount to withdraw from your bank account, it should be guaranteed that the money is getting out of the ATM before confirming the deduction from your account. If any task from the previous tasks fails, the overall withdraw transaction should be cancelled. For example, if any technical or mechanical error occurred after specifying the amount and deducting it from your account, that prevents the money from getting out the ATM, the operation should be canceled and the amount will be returned to your account.

先前的任务应作为一个单元运行,以使您的银行帐户保持一致状态。 这意味着,如果您指定从您的银行帐户中提取的金额,则应在确认从您的帐户中扣除该款项之前,确保该钱已从自动柜员机中取出。 如果先前任务中的任何任务失败,则应取消整体提款事务。 例如,如果在指定金额并将其从您的帐户中扣除后发生任何技术或机械错误,这会阻止钱从自动柜员机中取出,则应取消该操作并将金额退回到您的帐户中。

In SQL Server, the Transaction concept is highly required to maintain the integrity of data in a database, especially when executing multiple related tasks sequentially on different tables, databases or servers, or accessing the same records by more than one session concurrently. In all these cases, the transaction should work as one unit of failure or success.

在SQL Server中,非常需要事务处理概念来维护数据库中数据的完整性,尤其是在不同的表,数据库或服务器上顺序执行多个相关任务,或者同时通过多个会话访问同一条记录时。 在所有这些情况下,事务应作为失败或成功的一个单元来工作。

In the ATM withdraw example, the SQL Server Engine will commit the overall transaction, including the amount deduction from the bank account, when all the steps are performed successfully, and the money received by the user. To handle the concurrency, the SQL Server Engine holds a lock on the bank account during that transaction, to guarantee that no other transaction will be performed on the same account at the same time, that may result with dirty read or incorrect opera

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值