advancedAdvanced SQL — Stored Procedures, Functions, Triggers & Sequences

Why can a stored procedure COMMIT but a function cannot?

Functions execute as part of the calling statement's transaction — they inherit it and cannot start or end one. Procedures are invoked via CALL as their own top-level statement, and are explicitly allowed to issue COMMIT/ROLLBACK inside their own body, useful for long-running batch work that needs incremental commits.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Why do sequences guarantee uniqueness but not gaplessness?← Back to all SQL questions