mariadb-create-trigger

Documents MariaDB-specific CREATE TRIGGER syntax, ordering, restrictions, and common errors.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing CREATE TRIGGER statements for MariaDB often fails because standard SQL trigger assumptions do not hold: there is no ALTER TRIGGER, SQL SECURITY is invalid, and version-specific features like multi-event triggers only exist in MariaDB 12.0+. This Skill provides the exact MariaDB delta so generated or reviewed trigger code is syntactically and semantically correct. ## Core Features & Use Cases - MariaDB-specific grammar reference: Covers OR REPLACE, DEFINER, IF NOT EXISTS, FOLLOWS/PRECEDES trigger ordering, and multi-event triggers with INSERTING/UPDATING/DELETING predicates (since 12.0). - Common LLM trap table: Maps frequent mistakes (ALTER TRIGGER, NEW.col in DELETE triggers, COMMIT in trigger bodies, SQL SECURITY) to the correct MariaDB form. - Restriction and firing-behavior rules: Documents OLD/NEW row-reference rules, ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG, and how REPLACE, INSERT ... ON DUPLICATE KEY UPDATE, and LOAD DATA fire triggers. - Use Case: When asked to write an audit trigger that logs INSERT, UPDATE, and DELETE on a table, produce a single multi-event trigger for MariaDB 12.0+ or three correctly ordered per-event triggers for current LTS versions. ## Quick Start Ask the AI to write a MariaDB trigger that clamps a column value before update on a given table, and it will apply the correct MariaDB syntax and restrictions.

Frequently Asked Questions about mariadb-create-trigger

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

FAQPage Schema
How do I create a trigger in MariaDB?▼

Use CREATE TRIGGER with a trigger_time (BEFORE or AFTER), a trigger_event (INSERT, UPDATE, or DELETE), ON table_name FOR EACH ROW, and the trigger body. Multi-statement bodies require BEGIN ... END and the DELIMITER client command when typed interactively.

How do I modify or rename an existing trigger in MariaDB?▼

MariaDB has no ALTER TRIGGER statement. Use CREATE OR REPLACE TRIGGER to change the body or options, or DROP TRIGGER followed by CREATE TRIGGER to rename, since trigger names cannot be renamed in place.

Can one MariaDB trigger fire on multiple events like INSERT, UPDATE, and DELETE?▼

Since MariaDB 12.0, a single trigger can chain events with OR, such as BEFORE INSERT OR UPDATE OR DELETE, branching with INSERTING, UPDATING, and DELETING predicates. All current 10.x and 11.x LTS versions require one event per trigger.

Can a table have multiple BEFORE INSERT triggers in MariaDB?▼

Yes, MariaDB has always allowed multiple triggers for the same action time and event on one table. Control firing order with FOLLOWS or PRECEDES, and verify the order via ACTION_ORDER in INFORMATION_SCHEMA.TRIGGERS.

Why does my MariaDB trigger fail with ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG?▼

This error occurs when a trigger tries to modify a table that the invoking statement has already opened for read or write. Redesign the trigger to write to a different table or restructure the outer statement.

Can I create a trigger on a view or temporary table in MariaDB?▼

No, MariaDB triggers can only be attached to permanent base tables. Views and TEMPORARY tables are rejected, and triggers are always row-level since FOR EACH STATEMENT is not supported.