Search code examples
mysqlstored-procedurestransactions

Is MySQL stored procedure transactional by default?


I have a MySQL stored procedure which reads and updates multiple tables, so I want it to be a transaction. Is it already transactional by default? Or do i need to do something?

MySQL 5.0+


Solution

  • I don't believe so. According to the manual section on BEGIN...END statements:

    Within all stored programs (stored procedures and functions, triggers, and events), the parser treats BEGIN [WORK] as the beginning of a BEGIN ... END block. Begin a transaction in this context with START TRANSACTION instead.

    Also see the manual on START TRANSACTION, COMMIT, and ROLLBACK Syntax.