2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
The basic properties of transactions are ACID:
The ACID properties of database transactions refer to the four basic properties that ensure that the database can perform transaction operations reliably and correctly.Atomicity(Atomicity)、consistency(Consistency)、Isolation(Isolation)、PersistenceThe following is a detailed explanation of each feature:
Atomicity:
Atomicity means that a transaction is either fully executed or not executed at all. If an error or failure occurs during the transaction execution, the part of the operation that has been executed will be rolled back (undone), and the operation of the entire transaction will be as if it never happened.
For example, in a bank transfer, both steps of the transfer (debiting from one account and crediting to another) must either succeed or not. You cannot have a debit without a credit.
Consistency:
Consistency ensures that the database is always in a consistent state before and after a transaction is executed. At the beginning and end of a transaction, the database must satisfy all business rules and constraints.
For example, in a bank transfer, the total amount of an account should remain the same before and after the transaction. If an amount is deducted from one account, the corresponding amount should be added to the other account, and the total amount of the entire system remains consistent.
Isolation:
Isolation ensures that multiple concurrent transactions do not interfere with each other. Each transaction should be independent of other transactions during execution. The isolation level between transactions can be achieved through different locking mechanisms or multi-version concurrency control.
For example, in two concurrent bank transfer transactions, while one transaction is in progress, the other transaction should not see its uncommitted intermediate state.
Durability:
Persistence ensures that once a transaction is committed, its results are permanently saved in the database. Even if the system fails (such as power outage or crash), the submitted transaction results will not be lost.
For example, in a bank transfer, once the transfer transaction is successfully submitted, even if the system fails subsequently, the result of the transfer will not be lost, and the update of the account balance will be persisted.
These features together ensure the reliability and consistency of the database in transaction processing and ensure the integrity and accuracy of the data.
When designing multiple database operations, the following SQL is wrong. The two statements actually need to succeed or fail at the same time, but the current program does not meet my requirements.
Consistency is ensured through transactions