Get the App
SLTechnology News&Howtos  ›  Database  › 

What is a database transaction?

Shulou Source: shulou.com Published: 2022-06-01 13:06:03 10月13日 Update

What is a transaction?

A transaction is a whole made up of one or more sql statements, if all statements are executed successfully, then the changes will all take effect, if one sql statement will sell + 1, the next one will be + 1, if the second fails, then the sales volume will revoke the + 1 operation of the first sql statement, and only in this transaction will all statements be successfully executed before the changes will be added to the database. The characteristics of the transaction:

Atomicity

Atomicity means that all the operations of the transaction are either successful or all failed rollback, so if the operation of the transaction is successful, the knife database must be fully applied. If the operation fails, it will not have any impact on the database.

Consistency

Consistency means that a transaction must change the database from one consistent state to another, that is, a transaction must be in a consistent state before execution and after execution.

For example, assuming that the former sum of user An and user B is 5000, then no matter how the money transferred between An and B adds up to 5000, this is the consistency of the transaction.

Isolation

Isolation means that when multiple users access the database concurrently, such as manipulating the same table, the database opens transactions for each user and will not be disturbed by other operations

Concurrent transactions should be isolated from each other

Persistence

Persistence means that once a transaction is committed, the change to the data in the database is permanent. The storage engines that support transactions in Mysql are most used in mysql: INNODB, BDB, MYISAM, MEMORY, in which INNODB and BDB support transactions, and others do not support transactions.

Tags: Transactions data databases consistency users statements success status support isolation between atoms multiple that is engine persistence sales money transfer this is not Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MariaDB OPPO Reno Apple NVidia