本人最早接触的是oracle,最新学习了dm(达蒙)数据库。
每个数据库都有自己的优点,如果撇除价格因素,oracle无疑是第一名。
客观说,每个数据库都有自己的优点:
1)oracle,大而全,能够绝大部分业务场景,资料完备。
2)mysql,符合计算量小的业务场景(即计算中心在于应用服务器而不再数据库服务器),资料也齐全
3) dm,符合许多场景,语法上吸收了oracle和sqlserver的一些优点。
缺点:
1)oracle的安装和配置较为复杂
2)mysql,功能比较单一,而且配置也挺复杂的
3)dm,还不够完备,许多功能有待完善
--
作为关系数据库,它们至少都遵循sql-92标准,根据sql-92标准,定义了四种隔离级别,分别是:
1)读未提交
2)读已提交
3) 可重复读
4)串行
这四个隔离级别是为了解决三个异常读取情形:脏读、不可重复读、幻读
许多同学,总觉得这个不好记忆,这是因为例子不当导致的。
首先,必须理解三个异常情况的含义:
1)脏读-A transaction reads data that has been written by another transaction that has not been committed yet.
一个事务读取了另外一个事务尚未提交的数据。
2)不可重复读-A transaction rereads data it has previously read and finds that another committed transaction has modified or deleted the data.
For example, a user queries a row and then later queries the same row, only to discover that the data has changed.
当一个事务视图重新读取之前数据的时候,发现那些数据被别的事务修改过了,结果读取的和之前的一次不同
3)幻读-A transaction reruns a query returning a set of rows that satisfies a search condition and finds that another committed transaction has inserted additional rows that satisfy the condition.
For example, a transaction queries the number of employees. Five minutes later it performs the same query,
but now the number has increased by one because another user inserted a record for a new hire.
More data satisfies the query criteria than before, but unlike in a fuzzy read the previously read data is unchanged.
一个事务读取了满足条件的结果集合,并发现另外一个提交的事务插入了新的满足条件的数据。从解释上看,不可重复读和幻读的主要区别:不可重复都是数据被修改了,幻读是插入了新的数据。它们分别对应update和insert.
这三中情况简单来说就是:读了未确定的数据,读了被修改过的数据,读了同种查询条件下获得了更多的结果。
学习这个内容的时候,主要思考几个问题
1)异常读取情形有什么--即前文提到的三种异常?
2)隔离级别由什么,要解决哪些异常情形 -隔离级别通常就是SQL-92的四个
3)哪些业务场景应该使用哪些隔离级别--例如员工工资,银行存款报告、自动编号(读之后再修改)
4)数据库是如何实现隔离级别技术的--多版本,锁、临时存储
5)多版本一致性是什么--In Oracle Database, multiversioning is the ability to simultaneously materialize multiple versions of data
6)锁机制,行锁,表锁,乐观锁,悲观锁、回滚
我们为什么要考虑事务,是因为存在多并发,如果没有多并发,则无所谓!
当自己觉得不理解的时候,想想在并发情况下,多个进程(线程)执行如下操作的情形就能明白了:
select curno from tno
update tno curno=curno+1