Automatic Transaction Rollback
The question revolves around the behavior of transactions when an error occurs within a block of SQL statements enclosed by START TRANSACTION and COMMIT TRANSACTION. The OP notices that when a syntax error is encountered before the COMMIT TRANSACTION statement, the transaction is automatically rolled back.
Transaction Rollback Mechanism
No, transactions are not rolled back immediately upon encountering an error. However, certain client applications may adopt specific policies for error handling.
For example, in the mysql command-line client:
Customizing Rollback Policy
When building your own applications, you have control over transaction rollback policies. However, note that there are exceptions where a rollback is enforced:
For all other scenarios, if an error is encountered during a transaction, the error is returned, and the developer has the choice to commit or discard the transaction.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3