SQL 可序列化和可重复读隔离级别有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13374335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between serializable and repeatable read isolation level?
提问by Celeritas
What is the difference between serializable and repeatable read isolation level? Can anyone please give a simple example.
可序列化和可重复读隔离级别有什么区别?任何人都可以举一个简单的例子。
采纳答案by Thangamani Palanisamy
Summary:
概括:
In a Repeatable Read isolation level, new rows can be inserted into the dataset.
在可重复读隔离级别中,可以将新行插入到数据集中。
In a Serializable isolation level all the rows are locked for the duration of the transaction, no insert,update or delete is allowed.
在 Serializable 隔离级别中,所有行在事务期间都被锁定,不允许插入、更新或删除。
Please refer this for examples and explanation
请参阅此示例和说明
Isolation Level - serializable
隔离级别 - 可序列化
Isolation Level - repeatable-read
隔离级别 - 可重复读取
回答by Kristijan
Repeatable readprevents only non-repeatable read (so you can read the same data in the same transaction without fear of someone changing it - even though it's a rare need for doing it).
可重复读取仅防止不可重复读取(因此您可以在同一事务中读取相同的数据,而不必担心有人更改它——即使很少需要这样做)。
Serializableprevents both non-repeatable read and phantom rows (so you can't even INSERT data). That means you can READ and WRITE (SELECT, UPDATE) rows that are not included with serializable transaction, but you can't DELETE OR INSERT rows on TABLE level.
Serializable可防止不可重复读取和幻像行(因此您甚至不能插入数据)。这意味着您可以读取和写入(SELECT、UPDATE)未包含在可序列化事务中的行,但您不能在 TABLE 级别删除或插入行。
Both repeatable read and serializable are very strict and there is not always need for them!
可重复读取和可序列化都非常严格,并不总是需要它们!