mariadb-rename-table

Documents MariaDB RENAME TABLE syntax, atomicity, privileges, and cross-database restrictions.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing correct RENAME TABLE statements for MariaDB is error-prone because its behavior differs from other databases: it is fully atomic across multiple pairs, refuses to run inside transactions or under LOCK TABLES, requires a specific four-privilege set, and blocks cross-database moves for views and tables with triggers. This Skill gives AI agents the exact MariaDB-specific rules so generated or reviewed SQL avoids these pitfalls. ## Core Features & Use Cases - Atomic multi-table renames: Explains left-to-right execution with full rollback on any failure, enabling the classic one-statement table-swap pattern. - Restriction and privilege reference: Covers the ER_LOCK_OR_ACTIVE_TRANSACTION restriction, the ALTER+DROP / CREATE+INSERT privilege split, and cross-database move blocks for views and trigger-bearing tables. - Syntax details: Documents IF EXISTS, WAIT/NOWAIT lock-wait control, TEMPORARY table support, and the TABLE/TABLES interchangeability. - Use Case: When asked to swap a rebuilt table into production, the agent emits RENAME TABLE old_table TO backup_table, new_table TO old_table; as one atomic statement instead of unsafe multi-statement DROP/rename juggling. ## Quick Start Ask the agent to write or review a MariaDB RENAME TABLE statement, such as swapping two tables atomically or moving a table to another database.

Frequently Asked Questions about mariadb-rename-table

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

FAQPage Schema
How do I atomically swap two tables in MariaDB?▼

Use a single multi-pair RENAME TABLE statement: RENAME TABLE t1 TO tmp, t2 TO t1, tmp TO t2. The whole statement is atomic, so if any pair fails every rename is rolled back, making the swap safe without separate DROP or rename steps.

RENAME TABLE vs ALTER TABLE RENAME TO in MariaDB?▼

RENAME TABLE supports multiple comma-separated pairs executed atomically left-to-right, ideal for pure renames and swaps. ALTER TABLE ... RENAME TO renames a single table as one clause of a larger ALTER statement and lacks the all-or-nothing multi-pair semantics.

Can RENAME TABLE rename temporary tables in MariaDB?▼

Yes, RENAME TABLE works directly on TEMPORARY tables in MariaDB with identical syntax; there is no need to fall back to ALTER TABLE ... RENAME TO. Temporary-table renames are handled separately internally but behave the same for users.

Why does RENAME TABLE fail inside a transaction in MariaDB?▼

MariaDB raises ER_LOCK_OR_ACTIVE_TRANSACTION when RENAME TABLE is issued inside an active transaction or while LOCK TABLES is in effect. Unlike some DDL, it does not implicitly commit and proceed; the statement is refused before any table is touched.

What privileges are required for RENAME TABLE in MariaDB?▼

RENAME TABLE requires ALTER and DROP on the source table or database, plus CREATE and INSERT on the target table or database. All four privileges are checked across both names, so granting only a subset is a common under-provisioning mistake.

Can RENAME TABLE move a table to another database in MariaDB?▼

Yes, by qualifying names as db1.t TO db2.t, but two cases are blocked: views raise ER_FORBID_SCHEMA_CHANGE and tables with triggers raise ER_TRG_IN_WRONG_SCHEMA. Renaming a view within the same database works normally.