The transaction of the database is a collection of a series of operations (additions and deletions) in the database.
In general, the scope of the transaction depends on the business, such as transfer, modification of personal information
Transfer: Transfer $200 from account A to account B
- Deduction of 200 yuan from a account
- Add $200 to the B account
Modify personal Information: For example, personal information consists of 2 parts, which are stored in two tables "basic information Form" and "Payment information Form".
- Update the basic Information table information
- Update the "Payment Information form" information
In order to ensure that the transaction is correct, you need to have 4 characteristics, is the legendary acid:
- atomicity-atomicity: This sequence of operations for a transaction either completes (commits) all, or an exception (rollback) occurs halfway. That is to say, this series of operations of the transaction, is the smallest granularity that can not be divided, presents the atomicity.
- consistency-Consistency: The data for the database is consistent. The execution of a transaction must transform the database from one consistent state to another. For example, the above atomic operations must be committed or rolled back without allowing an intermediate state (so that the data is inconsistent). There is a close relationship between atomicity and consistency.
- isolation-Isolation: When multiple transactions concurrently execute on the same set of data, the degree of isolation between transactions is isolated and can be categorized into different levels.
- durability-Persistence: When the transaction is completed, the data is persisted to the database.
Characteristics of database transactions (ACID)