Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
For safety.
If the request consists of several actions
1) Find a record
2) Delete it
3) Create a new one
And suppose it is not possible to create a new record for some reason, then if the request is wrapped in a transaction, the deletion will be canceled.
A transaction is a group of sequential operations with a database, which is a logical unit of work with data. A transaction can be completed either entirely and successfully, respecting the integrity of the data and regardless of other concurrent transactions, or not completed at all, in which case it should not have any effect. Transactions are processed by transactional systems, in the course of which a history of transactions is created.
Transactions in MySQL are used for the same purpose as in any other database.
A classic example is the transfer of money from one account to another.
If you do this without a transaction, then a situation may occur when money is debited from the sender's account (the first request will be executed), but not credited to the recipient's account (the second question will not be executed for some reason).
The transaction guarantees that either both requests will be executed, or neither will be executed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question