文章目录
事务
事务的基本概念
简单来说,事务就是将一系列列数据库的基本操作看作一个基本执行单元。比如在银行转帐中可能设计多个基本数据库操作,但是转账这个操作本身应该被看作一个基本执行单元,因为我们不希望在转账的过程中出现异常,具体实例如下所示:
example transactions
x and y are bank balances -- records in database tables
x and y are on different servers (maybe at different banks)
x and y start out as $10
T1 and T2 are transactions
T1: transfer $1 from x to y
T2: audit, to check that no money is lost
T1: T2:
begin_xaction begin_xaction
add(x, 1) tmp1 = get(x)
add(y, -1)