Suppose we put a trigger on the purchase of goods, the trigger writes off funds from the user's account, is it safe? Will the transaction be automatically applied?
- 2The trigger works in the same transaction that generated it. If you commit a purchase transaction, then the debit will be recorded. And if you roll back the purchase, then the debit will be rolled out. A trigger for that and invented - Mike
- And if I don’t independently open a transaction for a purchase, doesn’nnnnb do it automatically for a pair purchase + debit (trigger)? - ndtvdx
- 2any operation in innoDB works in a transaction, even if you have not started it. Either everything is executed, or, in case of an error, everything will be rolled out. This is true if all participating innoDB tables. dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html Read the words: "For the transactional tables, the statement"
- that is, there should be no problems, I understand correctly? - ndtvdx
- Yes, there should be no problems - Mike
|
1 answer
Reply from comments from Mike
Any operation in InnoDB works in a transaction, even if you have not started it. Either everything is executed, or, in case of an error, everything will be rolled out. This is true if all participating InnoDB tables.
The trigger works in the same transaction that generated it. If you commit a purchase transaction, then the debit will be fixed, and if you roll back the purchase, the debit will be rolled back.
|