MySQL Learning notes-Transactions

Source: Internet
Author: User

A database transaction concept

Database Transaction is actually performing a series of operations on the database, while the transaction is either fully performing all operations or doing nothing at all, which guarantees the security and stability of the data.

Two- transaction features

Transactions have so-called acid properties, with the following characteristics:

1. atomicity (atomicity): atoms mean the smallest particles, or things that cannot be divided. The principle of non-re-division of database transactions is atomicity. All queries that make up a transaction must either be executed or all canceled.

2. Consistency (consistency): refers to the data rules, should be consistent before/after the transaction.

3. Isolation (Isolation): Simply put, the operation of a transaction is not visible to other transactions.

4. persistence (Durability): When a transaction is complete, its impact should be preserved and cannot be undone.

Three- transaction usage steps

1. Open transaction: Start transaction;

2. Perform SQL operations;

3. Commit or Rollback (commit/rollback)

Four operational examples

1. Create the following table and insert two data

Mysql> CREATE Table A (

ID int,

money int);

Mysql> INSERT into a values (1,5000), (2,5000);

2. The Black window is assumed to be the server side, the Blue window is assumed to be the client, querying the data separately, as follows

3. The server opened the transaction, while performing SQL operations, 1th to 2nd to transfer 500 yuan, while the server in the absence of a commit operation, the client will still see the original data.

4. The server commits the confirmation (commit) operation, the client sees that the data has changed

5. If the server executes the same transaction again, but finally cancels (rollback) The transaction, the data that the client sees does not change

MySQL Learning notes-Transactions

Related Article

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.