mariadb-system-versioned-tables

Implement automatic row history and point-in-time queries using MariaDB system-versioned tables.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Tracking data changes over time usually requires custom triggers, audit tables, or application logic. This Skill guides you through MariaDB's built-in system-versioned tables, which automatically record the full history of every row change directly in the storage engine, enabling audit trails, compliance reporting, and point-in-time queries without extra code. ## Core Features & Use Cases - Automatic Row History: Create tables with WITH SYSTEM VERSIONING so every INSERT, UPDATE, and DELETE is tracked with hidden ROW_START and ROW_END columns. - Point-in-Time Queries: Query past data states using FOR SYSTEM_TIME AS OF, BETWEEN, FROM ... TO, or ALL clauses, or set a session-wide snapshot with system_versioning_asof. - History Management: Control growth with PARTITION BY SYSTEM_TIME, purge old records with DELETE HISTORY, and handle backups via mariadb-dump --dump-history. - Use Case: A compliance team needs to prove what customer data existed on a specific date for GDPR. Instead of building trigger-based audit tables, they enable system versioning and run SELECT * FROM customers FOR SYSTEM_TIME AS OF '2025-06-01'. ## Quick Start Ask the AI to create a MariaDB system-versioned table for employee records and show how to query its state as of a past date.

Frequently Asked Questions about mariadb-system-versioned-tables

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

FAQPage Schema
How do I create a system-versioned table in MariaDB?▼

Create a system-versioned table by appending WITH SYSTEM VERSIONING to your CREATE TABLE statement. MariaDB automatically adds hidden ROW_START and ROW_END timestamp columns, and every INSERT, UPDATE, or DELETE generates a history row. For existing tables, run ALTER TABLE t ADD SYSTEM VERSIONING.

How to query historical data at a specific point in time in MariaDB?▼

Use the FOR SYSTEM_TIME clause directly after the table name, such as SELECT * FROM t FOR SYSTEM_TIME AS OF '2026-01-01'. Variants include BETWEEN, FROM ... TO, and ALL for full history. You can also set system_versioning_asof to apply a snapshot to all session queries.

Does MySQL support system-versioned temporal tables?▼

No, MySQL has no equivalent to system-versioned tables. This feature is unique to MariaDB among MySQL-compatible databases and has been available since MariaDB 10.3. SQL Server temporal syntax also differs and does not translate directly.

Why does TRUNCATE fail on a versioned table in MariaDB?▼

TRUNCATE is prohibited on system-versioned tables and raises error 4137 to protect history integrity. Use DELETE HISTORY FROM t BEFORE SYSTEM_TIME 'date' to purge old history, or manage historical partitions with ALTER TABLE DROP PARTITION instead.

Why does ALTER TABLE fail on a system-versioned table?▼

By default, ALTER TABLE on a versioned table raises an error to protect history integrity. Set system_versioning_alter_history = KEEP before altering, then restore it to ERROR afterward. Historical rows for newly added columns will contain NULL values.

Does mysqldump back up historical rows from versioned tables?▼

No, mysqldump and mariadb-dump skip historical rows by default. Use mariadb-dump --dump-history (MariaDB 10.11+) to include them, and set system_versioning_insert_history=ON plus secure_timestamp on restore so the loader can write ROW_START and ROW_END values.