<p>MySQL blocks COMMIT or ROLLBACK inside a stored function or trigger and raises error 1422.</p>
<p>MySQL Error 1422 ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG occurs when a statement causes an explicit or implicit COMMIT or ROLLBACK inside a stored function or trigger. Remove transaction control from the routine or move the logic to application code to resolve the issue.</p>
Explicit or implicit commit is not allowed in stored
MySQL throws error 1422 with the message Explicit or implicit commit is not allowed in stored function or trigger when a stored function or trigger attempts to execute a COMMIT, ROLLBACK, START TRANSACTION, or any statement that forces an implicit commit such as ALTER TABLE.
The server detects the offending statement while executing the routine body. The check is performed for both explicit transaction commands and implicitly committing DDL. If detected, execution halts and error 1422 is returned to the caller.
Stored functions and triggers must remain atomic so they can be executed safely within larger transactions. Allowing commits would break atomicity, possibly leave data half-written, and interfere with the caller’s transaction boundaries. MySQL therefore blocks any commit or rollback inside these contexts.
An unexpected 1422 error rolls back the current statement, leaving the surrounding transaction unchanged. Calls from ORMs, batch scripts, or Galaxy’s SQL editor will fail until the routine is corrected, leading to application errors or failed deployments.
The routine body directly calls COMMIT or ROLLBACK to finalise work.
Statements such as ALTER TABLE, CREATE INDEX, or DROP TABLE auto-commit and trigger error 1422 when run inside a function or trigger.
Beginning a new transaction inside a stored function or trigger is also forbidden and raises the same error.
A nested procedure or function containing a commit causes the error to bubble up to the original function or trigger.
Raised when certain statements, such as LOCK TABLES, are executed inside a stored function or trigger.
Can appear when DDL inside transactions silently commits and conflicts with routine logic.
Triggered if you attempt to change transaction-related system variables inside a function or trigger.
Yes. Procedures are allowed to manage their own transactions because they are not required to be deterministic or atomic like functions and triggers.
No. Pure SELECT statements do not commit. Only DDL or explicit transaction commands raise error 1422.
All maintained MySQL versions 5.5 and later forbid commits inside stored functions and triggers.
Galaxy’s linting surfaces transaction commands inside routines during edit time, allowing you to refactor before running the code.