Transaction can guarantee the atomicity of multiple operations, either all succeed or all fail. For the database, the transaction guarantees that the batch of DML will either succeed or fail. The transaction has four characteristics ACID.
● Atomicity
All operations in the entire transaction must be completed as a unit (or all cancelled)
● Consistency
Before the transaction begins and after the end, the database remains in a consistent state
● Isolation (Isolation)
A transaction will not affect the operation of other transactions
● Durability
After the transaction is completed, the changes made by the transaction to the database will be persistently stored in the database and will not be rolled back
There are some concepts in the transaction:
● Transaction: a batch of operations (a group of DML)
● Start Transaction
● Rollback transaction (rollback)
● Commit the transaction (commit)
● SET AUTOCOMMIT: Disable or enable the automatic commit mode of transactions
When the DML statement is executed, it is actually to start a transaction;
Note about transaction rollback: only insert, delete, and update statements can be rolled back, but select cannot be rolled back (rolling back select has no meaning). For create, drop, and alter transactions that cannot be rolled back, they only have an effect on DML.
Note: The transaction ends after rollback or commit.