V
V
Vadim9972014-10-13 16:12:28
PHP
Vadim997, 2014-10-13 16:12:28

What are transactions in mysql used for?

What are transactions used for in mysql queries, if you can use them without them?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Gogolinsky, 2014-10-13
@Vadim997

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.

S
Sergey, 2014-10-13
Protko @Fesor

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.

(c) Wikipedia
That is, if you need to make a transaction, make a transaction. If not, we don't do it... The question is what level of reliability do you want to get.

A
Anton, 2014-10-13
@zeromodule

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 question

Ask a Question

731 491 924 answers to any question