mariadb-delete

Documents MariaDB-specific DELETE syntax including RETURNING, multi-table forms, and temporal-table deletion.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Standard SQL DELETE knowledge is not enough for MariaDB: agents often miss MariaDB-specific features like RETURNING, multi-table ORDER BY/LIMIT, DELETE HISTORY, and FOR PORTION OF, or fall into traps like expecting DELETE to reset AUTO_INCREMENT. This Skill provides the exact delta between standard SQL and MariaDB DELETE behavior. ## Core Features & Use Cases - MariaDB DELETE syntax reference: Covers single-table DELETE with PARTITION, aliases, index hints, ORDER BY/LIMIT, and the QUICK/LOW_PRIORITY/IGNORE modifiers with their engine limits. - Multi-table and RETURNING forms: Documents both multi-table syntaxes (DELETE ... FROM and DELETE FROM ... USING) with ORDER BY/LIMIT since 11.8, plus single-table RETURNING of deleted rows. - Temporal table deletion: Explains DELETE HISTORY for system-versioned tables and FOR PORTION OF for application-time-period tables, plus DELETE-vs-TRUNCATE differences. - Use Case: When asked to write a query that deletes stale sessions and returns the deleted IDs in one round trip, the agent produces DELETE FROM sessions WHERE expires_at < NOW() RETURNING id, user_id instead of a two-statement SELECT-then-DELETE approach. ## Quick Start Ask the agent to write or review a MariaDB DELETE statement, such as deleting rows with RETURNING or pruning history from a system-versioned table.

Frequently Asked Questions about mariadb-delete

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

FAQPage Schema
How do I delete rows and return them in one MariaDB query?▼

Use DELETE with the RETURNING clause, for example `DELETE FROM sessions WHERE expires_at < NOW() RETURNING id, user_id`. RETURNING is single-table only and supports expressions and aliases, but not aggregates.

Can MariaDB multi-table DELETE use ORDER BY and LIMIT?▼

Yes, since MariaDB 11.8 multi-table DELETE supports ORDER BY and LIMIT, such as `DELETE t1.*, t2.* FROM t1 JOIN t2 ON ... ORDER BY t1.id DESC LIMIT 3`. Both multi-table syntaxes are valid, but RETURNING is not allowed on either.

What is the difference between DELETE and TRUNCATE in MariaDB?▼

DELETE is transactional, fires ON DELETE triggers, and follows FK cascades, while TRUNCATE performs an implicit commit, skips triggers, errors on FK-referenced tables, and resets AUTO_INCREMENT. DELETE does not reset AUTO_INCREMENT even without a WHERE clause.

How do I delete history from a system-versioned table in MariaDB?▼

Use `DELETE HISTORY FROM t BEFORE SYSTEM_TIME '2024-01-01'`, which requires the dedicated DELETE HISTORY privilege. A plain DELETE only moves rows to history rather than removing them.

Do QUICK and LOW_PRIORITY modifiers work on InnoDB tables?▼

No, QUICK and LOW_PRIORITY are table-lock-engine concerns for MyISAM and Aria. QUICK skips index-block merging and LOW_PRIORITY waits for readers; neither has any effect on InnoDB.

Can a MariaDB DELETE reference its target table in a subquery?▼

Yes, MariaDB allows deleting from a table referenced in its own subquery, such as `DELETE FROM t1 WHERE c1 IN (SELECT c1 FROM t1 b WHERE b.c2 = 0)`. The restriction only existed on long-unmaintained versions.