Name
SQL-02: Don’t leave transactions “dangling”
Synopsis
Once you start a transaction, you should take responsibility
for completing the transaction. Since transactions lock rows and
potentially block other transactions, you need to ensure that
transactions do not persist indefinitely. Generally, you should
place the START TRANSACTION
and
COMMIT
or ROLLBACK
statements in the same stored
program. This program may also call other programs, and you need
to make sure that these called programs do not contain
transactional code.
There are some exceptions to this recommendation. In particular, modular design might prompt you to break down a transaction into separate modules and control the overall transaction state from a master procedure.
Get MySQL Stored Procedure Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.