Back (Current repo: scraps)

random scraps and notes that are useful to me
To clone this repository:
git clone https://git.viktor1993.net/scraps.git
Log | Download | Files | Refs

sequences_in_mariadb.txt (543B)


Q: What is the purpose of a sequence in MariaDB?

A: A sequence is a database object that generates a series of unique, ordered numeric values kind of like a counter managed by the database, separate from any table.

It is independent of tables, the same sequence can be shared between multiple tables if needed. Can customize start value, increment, min/max and whether it cycles.

CREATE SEQUENCE invoice_seq
  START WITH 1000
  INCREMENT BY 1;

INSERT INTO invoices (id, customer, amount)
VALUES (NEXT VALUE FOR invoice_seq, 'Alice', 500);