Common SQL Errors

MySQL Error 1422: ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>MySQL blocks COMMIT or ROLLBACK inside a stored function or trigger and raises error 1422.</p>

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1422 ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG?

<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>

Error Highlights

Typical Error Message

Explicit or implicit commit is not allowed in stored

Error Type

Transaction Error

Language

MySQL

Symbol

ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG

Error Code

1422

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 1422 ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG?

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.

When does this error occur?

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.

Why does MySQL forbid commits inside routines?

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.

Impact on applications

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.

Common Causes

Explicit COMMIT or ROLLBACK

The routine body directly calls COMMIT or ROLLBACK to finalise work.

Implicit commit via DDL

Statements such as ALTER TABLE, CREATE INDEX, or DROP TABLE auto-commit and trigger error 1422 when run inside a function or trigger.

START TRANSACTION inside routine

Beginning a new transaction inside a stored function or trigger is also forbidden and raises the same error.

Calling another routine that commits

A nested procedure or function containing a commit causes the error to bubble up to the original function or trigger.

Related Errors

Error 1436: ER_NOT_ALLOWED_COMMAND

Raised when certain statements, such as LOCK TABLES, are executed inside a stored function or trigger.

Error 1105: ER_UNKNOWN_ERROR with implicit commit

Can appear when DDL inside transactions silently commits and conflicts with routine logic.

Error 1193: ER_UNKNOWN_SYSTEM_VARIABLE

Triggered if you attempt to change transaction-related system variables inside a function or trigger.

FAQs

Can I call COMMIT inside a stored procedure?

Yes. Procedures are allowed to manage their own transactions because they are not required to be deterministic or atomic like functions and triggers.

Does SELECT ... INTO cause error 1422?

No. Pure SELECT statements do not commit. Only DDL or explicit transaction commands raise error 1422.

Which MySQL versions enforce this rule?

All maintained MySQL versions 5.5 and later forbid commits inside stored functions and triggers.

How does Galaxy help avoid this error?

Galaxy’s linting surfaces transaction commands inside routines during edit time, allowing you to refactor before running the code.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo