mariadb-transactions

Documents MariaDB-specific transaction control syntax, implicit commit rules, and common LLM traps.

28|115|Updated Jan 28, 2025
One-click install
npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-transactions-mariadb-corporation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mariadb-transactions
Source: https://github.com/mariadb-corporation/mariadb-docs/tree/main/agent-skills/granular/statements/mariadb-transactions
Command: npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-transactions-mariadb-corporation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? LLMs frequently generate transaction-control SQL that is valid in standard SQL but wrong or misleading in MariaDB — such as using BEGIN inside stored routines, wrapping DDL in transactions expecting rollback, or assuming autocommit is off by default. This Skill provides the exact MariaDB delta so generated transaction statements behave correctly. ## Core Features & Use Cases - MariaDB-specific syntax reference: Covers START TRANSACTION / BEGIN, WITH CONSISTENT SNAPSHOT, READ ONLY / READ WRITE, COMMIT / ROLLBACK with AND CHAIN and RELEASE, SAVEPOINT, and RELEASE SAVEPOINT. - Implicit commit and autocommit rules: Documents which statements commit implicitly before execution, autocommit defaults, the in_transaction session variable, and completion_type behavior. - LLM trap table: Maps common incorrect patterns (e.g., DDL rollback attempts, nested START TRANSACTION, LOCK TABLES interactions) to the correct MariaDB forms. - Use Case: When asked to write a retry loop that commits and immediately starts a new transaction, the agent uses COMMIT AND CHAIN instead of separate COMMIT and START TRANSACTION statements, preserving isolation level and access mode. ## Quick Start Ask the agent to write or review MariaDB transaction-control statements, such as generating a stored procedure that starts a transaction with START TRANSACTION and rolls back to a savepoint on error.

Frequently Asked Questions about mariadb-transactions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I start a transaction in MariaDB?▼

Use START TRANSACTION or BEGIN at the top level of a session. START TRANSACTION additionally supports WITH CONSISTENT SNAPSHOT, READ ONLY, and READ WRITE clauses. Inside stored procedures, only START TRANSACTION works because BEGIN opens a block instead.

Can I roll back DDL statements like CREATE TABLE in MariaDB?▼

No, DDL statements cause an implicit commit before execution and cannot be rolled back, even if the statement itself fails. Exceptions include CREATE TABLE and DROP TABLE on TEMPORARY tables, which do not trigger an implicit commit.

Does MariaDB support nested transactions with START TRANSACTION?▼

No, issuing START TRANSACTION while a transaction is open implicitly commits the current transaction first, then starts a new one. Use SAVEPOINT and ROLLBACK TO SAVEPOINT for sub-transaction rollback points instead.

Why does BEGIN not start a transaction inside a MariaDB stored procedure?▼

Inside stored routines, BEGIN ... END is a block delimiter, not a transaction starter. Transactions are not allowed in stored functions or triggers at all; in stored procedures and events, use START TRANSACTION explicitly.

How do I check if a transaction is open in MariaDB?▼

Query the read-only session variable in_transaction, which returns 1 inside a transaction and 0 otherwise. This avoids tracking transaction state in application code.

How do I automatically kill idle transactions in MariaDB?▼

Set idle_transaction_timeout to bound all idle transactions, or use idle_write_transaction_timeout and idle_readonly_transaction_timeout for specific types. These differ from wait_timeout, which closes idle connections rather than transactions.