日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

事务隔离级别(IsolationLevel)

發(fā)布時間:2023/12/15 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 事务隔离级别(IsolationLevel) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

來源:https://www.cnblogs.com/wms01/p/6183241.html

事務隔離級別(IsolationLevel)

事務的特性(ACID) 1、原子性(Atomicity)事物是數據庫的邏輯工作單位,事務中的諸多操作要么全做要么全不做 2、一致性(Consistency)事務執(zhí)行結果必須是使數據庫從一個一致性狀態(tài)變到另一個一致性狀態(tài) 3、隔離性(Isolation)一個數據的執(zhí)行不能被其他事務干擾 4、持續(xù)性/永久性(Durability)一個事務一旦提交,它對數據庫中的數據改變是永久性的

隔離級別與并發(fā)性是互為矛盾的:隔離程度越高,數據庫的并發(fā)性越差;隔離程度越低,數據庫的并發(fā)性越好,這點很好理解

事務的隔離級別(IsolationLevel)

1 // 摘要: 2 // Specifies the transaction locking behavior for the connection.3 public enum IsolationLevel4 {5 // 摘要: 6 // A different isolation level than the one specified is being used, but the7 // level cannot be determined.8 Unspecified = -1,9 // 10 // 摘要: 11 // The pending changes from more highly isolated transactions cannot be overwritten. 12 Chaos = 16, 13 // 14 // 摘要: 15 // A dirty read is possible, meaning that no shared locks are issued and no 16 // exclusive locks are honored. 17 ReadUncommitted = 256, 18 // 19 // 摘要: 20 // Shared locks are held while the data is being read to avoid dirty reads, 21 // but the data can be changed before the end of the transaction, resulting 22 // in non-repeatable reads or phantom data. 23 ReadCommitted = 4096, 24 // 25 // 摘要: 26 // Locks are placed on all data that is used in a query, preventing other users 27 // from updating the data. Prevents non-repeatable reads but phantom rows are 28 // still possible. 29 RepeatableRead = 65536, 30 // 31 // 摘要: 32 // A range lock is placed on the System.Data.DataSet, preventing other users 33 // from updating or inserting rows into the dataset until the transaction is 34 // complete. 35 Serializable = 1048576, 36 // 37 // 摘要: 38 // Reduces blocking by storing a version of data that one application can read 39 // while another is modifying the same data. Indicates that from one transaction 40 // you cannot see changes made in other transactions, even if you requery. 41 Snapshot = 16777216, 42 }

常用狀態(tài)分析:

  1、ReadUncommitted

    表示:未提交讀。當事務A更新某條數據的時候,不容許其他事務來更新該數據,但可以進行讀取操作

  2、ReadCommitted

    表示:提交讀。當事務A更新數據時,不容許其他事務進行任何的操作包括讀取,但事務A讀取時,其他事務可以進行讀取、更新

  3、RepeatableRead

    表示:重復讀。當事務A更新數據時,不容許其他事務進行任何的操作,但是當事務A進行讀取的時候,其他事務只能讀取,不能更新

  4、Serializable

    表示:序列化。最嚴格的隔離級別,當然并發(fā)性也是最差的,事務必須依次進行。

?讀取現象

?通過一些現象,可以反映出隔離級別的效果。這些現象有:

  • 更新丟失(lost update):當系統允許兩個事務同時更新同一數據時,發(fā)生更新丟失。
  • 臟讀(dirty read):當一個事務讀取另一個事務尚未提交的修改時,產生臟讀。
  • 不重復讀(nonrepeatable read):同一查詢在同一事務中多次進行,由于其他提交事務所做的修改或刪除,每次返回不同的結果集,此時發(fā)生非重復讀。(A transaction rereads data it has previously read and finds that another committed transaction has modified or deleted the data.? )
  • 幻讀(phantom read):同一查詢在同一事務中多次進行,由于其他提交事務所做的插入操作,每次返回不同的結果集,此時發(fā)生幻像讀。(A transaction reexecutes 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.? )

隔離級別與讀取現象

隔離級別臟讀???Dirty Read?不可重復讀取? NonRepeatable Read?幻讀?Phantom Read?
未授權讀取/未提交讀?? read uncommitted可能發(fā)生可能發(fā)生可能發(fā)生
授權讀取/提交讀????????? read committed-可能發(fā)生可能發(fā)生
重復讀?????? ????????????????? read repeatable--可能發(fā)生
序列化???????????????? ?????? serializable????????---

常見數據庫的默認級別

數據庫默認隔離級別
Oracleread committed
SqlServerread committed
MySQL(InnoDB)Read-Repeatable

?

總結

以上是生活随笔為你收集整理的事务隔离级别(IsolationLevel)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。