码迷,mamicode.com
首页 > 数据库 > 详细

数据库复习⑩

时间:2016-06-19 15:34:01      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:

数据库复习⑩

2016年6月19日

13:40

Main Transactions 事务

1.Transaction Concept 事务的概念

A transaction is a unit of program execution that accesses and possibly updates various data items.

事务是并发控制的单位,是用户定义的一个操作序列。这些操作要么都做,要么都不做,是一个不可分割的工作单位。通过事务,SQL Server能将逻辑相关的一组操作绑定在一起,以便服务器保持数据的完整性。

2.事务的开始以及结束

事务通常是以BEGIN TRANSACTION开始,以COMMIT或ROLLBACK结束。

COMMIT表示提交,即提交事务的所有操作。具体地说就是将事务中所有对数据库的更新写回到磁盘上的物理数据库中去,事务正常结束。

ROLLBACK表示回滚,即在事务运行的过程中发生了某种故障,事务不能继续进行,系统将事务中对数据库的所有以完成的操作全部撤消,滚回到事务开始的状态。

3.ACID Properties事务的特性(ACID特性)

A:原子性(Atomicity)

Either all operations of the transaction are properly reflected in the database or none are

事务是数据库的逻辑工作单位,事务中包括的诸操作要么全做,要么全不做。

B:一致性(Consistency)

Execution of a transaction in isolation preserves the consistency of the database.

事务执行的结果必须是使数据库从一个一致性状态变到另一个一致性状态。一致性与原子性是密切相关的。

C:隔离性(Isolation)

Although multiple transactions may execute concurrently, each transaction must be unaware of other concurrently executing transactions. Intermediate transaction results must be hidden from other concurrently executed transactions.

一个事务的执行不能被其他事务干扰。

D:持续性/永久性(Durability)

After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures.

一个事务一旦提交,它对数据库中数据的改变就应该是永久性的。

技术分享

4.Transaction State事务的状态

Active 初始化的状态

Partially committed 在最后一条语句被执行前的状态

Failed 正常的运行无法继续处理的状态

Aborted在事务被回滚,数据库中存储的数据状态回退到最原始的状态。

Committed 在成功完成该事务之后的状态

技术分享

5. Concurrent Executions事务的并发运行

Multiple transactions are allowed to run concurrently in the system. Advantages are:

increased processor and disk utilization

reduced average response time

多个事务允许同时在一个系统下运行,具有以下的优点:

增加处理器和磁盘的利用率

缩短了平均响应时间

6.Schedule 调度表/进度表

Schedule – a sequences of instructions that specify the chronological order in which instructions of concurrent transactions are executed

进度表是有顺序的指令集合,明确了并发调度时并发事务的指令执行的时间顺序。

技术分享

技术分享

技术分享

技术分享

7.Conflict Serializability 可串行化的

技术分享

检验是否可以串行化调度的方法:

Precedence graph 前驱图

技术分享

Recoverable Schedules可恢复的调度

技术分享

Cascading Rollbacks 级联回滚

技术分享

相关博文链接:http://www.cnblogs.com/zpfbuaa/p/5479733.html

数据库复习⑩

标签:

原文地址:http://www.cnblogs.com/zpfbuaa/p/5598011.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!