Summary of database transaction isolation levels

Source: Internet
Author: User

First, MySQL default isolation level is repeatable READ
1. Querying a record two times in a transaction, the result is always the value before the start of the transaction. Whether or not another transaction has changed this record,
2. If you save a record in a transaction,

1) If this record has been changed by another already closed transaction, this transaction will overwrite the record.

2) If another transaction changes this record first and does not commit, the transaction will be stuck and waiting. This transaction continues to run until another transaction has ended. The modification affects 0 records, which means that the data is not changed (the equivalent of the modification failed, white changed.) ) (Avoid the second type of update loss)

Second, Oracle default read commited
1. A two-time query for a transaction may be different. Always be able to find the latest.
2. If you save a record in a transaction,

1) If this record has been changed by another already closed transaction, this transaction will overwrite the record. Same as MySQL.

2) If another transaction changes this record first and does not commit, the transaction will be stuck and waiting. This transaction continues to run until another transaction has ended. The difference is that this change will affect the record is not 0, that is, the modification will take effect (overwrite the first transaction modification). (second type of update is missing)

Test code for MySQL

-- ------------------------------Table structure for test-- ----------------------------DROP TABLE IF EXISTS' test ';CREATE TABLE' Test ' (' ID ')int( One)DEFAULT NULL, ' name 'varchar(255)DEFAULT NULL) ENGINE=InnoDBDEFAULTCHARSET=latin1;-- ------------------------------Records of Test-- ----------------------------INSERT  into' Test 'VALUES('1','5');INSERT  into' Test 'VALUES('2','3');SELECT @ @tx_isolation;SELECT @ @global. tx_isolation;SetSessionTransaction Isolation  Level Read committed;SetSessionTransaction Isolation  Level Read Uncommitted;SetSessionTransaction Isolation  Level  Repeatable Read;SetGlobalTransaction Isolation  Level Read committed;SetGlobalTransaction Isolation  Level Read Uncommitted;SetGlobalTransaction Isolation  Level  Repeatable Read; startTransaction;Select *  fromtest;UpdateTestSetName='2' whereId=2;Select *  fromtest;Commit;
View Code

Summary of database transaction isolation levels

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.