MariaDB SEQUENCE Engine
MariaDB SEQUENCE Engine is a SQL statement in the MySQL Specific category. MariaDB 10.3+: supports standard SQL SEQUENCE objects, unlike MySQL which requires AUTO_INCREMENT. The syntax is CREATE SEQUENCE seq_name START WITH 1 INCREMENT BY 1;. It returns sequence value. A typical example: CREATE SEQUENCE emp_id_seq START WITH 1000 INCREMENT BY 1 MINVALUE 1 MAXVALUE 999999 CYCLE CACHE 20; SELECT NEXTVAL(emp_id_seq); -- 1000 SELECT NEXTVAL(emp_id_seq); -- 1001 -- Use as DEFAULT: CREATE TABLE employees ( id INT PRIMARY KEY DEFAULT NEXTVAL(emp_id_seq), name VARCHAR(100) ); -- MariaDB-only syntax: -- NEXTVAL() / NEXT VALUE FOR -- SETVAL() / LASTVAL() A close relative is AUTO_INCREMENT, which mySQL auto-generates sequential integer values for this column. Commonly used with PRIMARY KEY. A close relative is ENGINE, which specifies the MySQL storage engine. InnoDB (default) supports transactions and foreign keys. MyISAM is faster for read-heavy. A close relative is LAST_INSERT_ID(), which returns the AUTO_INCREMENT value generated by the most recent INSERT in the current connection.