A database transaction is a sequence of database operations that accesses and may operate various data items. These operations are either all executed or none are executed. They are an indivisible unit of work. A transaction consists of all database operations performed between the start and end of a transaction.
【Recommended tutorial: MySQL tutorial】
Transactions in the database
A database transaction is a sequence of database operations that accesses and may operate various data items. These operations are either all executed or none are executed. Yes An indivisible unit of work. A transaction consists of all database operations performed between the start and end of a transaction.
A transaction is a series of operations performed as a logical unit. A logical unit of work must have four properties, called ACID (Atomicity, Consistency, Isolation, and Durability) properties. Only in this way can it become A transaction.
Atomicity
Transactions must be atomic units of work; either all or none of their data modifications are executed.
Consistency
When a transaction is completed, all data must be consistent. In the relevant database, all rules must be applied to transaction modifications to maintain the integrity of all data. At the end of the transaction, all internal data structures (such as B-tree indexes or doubly linked lists) must be correct.
Isolation
Modifications made by concurrent transactions must be isolated from modifications made by any other concurrent transactions. The state of the data when a transaction views the data is either the state before it was modified by another concurrent transaction, or the state after another transaction modified it. The transaction will not view the data in the intermediate state. This is called serializability because it enables the starting data to be reloaded and a series of transactions to be replayed so that the data ends in the same state as the original transaction execution.
Persistence
After a transaction is completed, its impact on the system is permanent. This modification will be maintained even if there is a system failure.
The above is the detailed content of What is a database transaction?. For more information, please follow other related articles on the PHP Chinese website!