mariadb-create-sequence

Generates and reviews MariaDB CREATE SEQUENCE statements with correct syntax, defaults, and replication behavior.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? MariaDB sequences differ from standard-SQL and Oracle sequences in subtle ways — they are ordinary tables wrapped with sequence semantics, default to CACHE 1000, require row-based binlogging, and special-case INCREMENT BY 0 for multi-master setups. This Skill prevents LLMs from generating incorrect CREATE SEQUENCE statements that fail at runtime or behave unexpectedly in production. ## Core Features & Use Cases - Dialect-accurate syntax generation: Produces CREATE SEQUENCE statements with correct clause ordering, defaults (BIGINT SIGNED, CACHE 1000, NOCYCLE), and version-specific features like the AS type clause since 11.5. - Gotcha detection: Flags common mistakes such as using DROP/CREATE instead of atomic CREATE OR REPLACE, assuming statement-based binlogging works, or combining AS <type> with other ALTER SEQUENCE clauses. - Use Case: When designing a Galera cluster schema, ask for a sequence definition and receive CREATE SEQUENCE s_mm INCREMENT BY 0; — the documented form that defers to auto_increment_increment/offset for collision-free values across nodes. ## Quick Start Ask the AI to write a MariaDB CREATE SEQUENCE statement for your use case, such as a cached sequence starting at 100 with increment 10, and review it against MariaDB-specific behavior.

Frequently Asked Questions about mariadb-create-sequence

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

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

Use CREATE SEQUENCE with optional clauses like START WITH, INCREMENT BY, MINVALUE, MAXVALUE, CACHE, and CYCLE in any order. For example, CREATE SEQUENCE s START WITH 100 INCREMENT BY 10 creates a cached sequence beginning at 100.

How to get the next sequence value in MariaDB?▼

MariaDB supports three access forms: ANSI NEXT VALUE FOR seq, PostgreSQL-style NEXTVAL(seq), and Oracle-mode seq.nextval when SQL_MODE=ORACLE is set. PREVIOUS VALUE FOR and LASTVAL return the last value generated by the current connection.

Does MariaDB CREATE SEQUENCE work with Galera or multi-master replication?▼

Yes, but set INCREMENT BY 0 so the sequence defers to the session's auto_increment_increment and auto_increment_offset settings. This guarantees non-colliding values per node, which is MariaDB's documented approach for multi-master and Galera setups.

Why does SELECT NEXT VALUE FOR fail with statement-based binlogging?▼

Reading the next sequence value mutates the sequence's backing row and is always logged as a row event, which statement-based logging cannot represent. Under BINLOG_FORMAT=STATEMENT it raises an error; use ROW or MIXED instead.

What is the difference between MariaDB sequences and the SEQUENCE storage engine?▼

A CREATE SEQUENCE object is an ordinary table on any transactional engine wrapped with sequence semantics. The SEQUENCE storage engine is an unrelated virtual row generator behind seq_1_to_N-style table names used for generating rows in queries.

Can I change a sequence's data type with ALTER SEQUENCE in MariaDB?▼

Yes, since 11.5, but the AS <type> clause cannot be combined with any other clause in the same ALTER SEQUENCE statement — the parser rejects it. Issue the type change alone; it runs internally as a full ALTER TABLE column change.