Sequence has run out of values
ER_SEQUENCE_RUN_OUT (4035) is returned when a SEQUENCE object has exhausted all available values in its defined range and CYCLE is not enabled.
CREATE SEQUENCE s START WITH 1 MINVALUE 1 MAXVALUE 3 NO CYCLE; SELECT NEXT VALUE FOR s; -- 1 SELECT NEXT VALUE FOR s; -- 2 SELECT NEXT VALUE FOR s; -- 3 SELECT NEXT VALUE FOR s; -- ERROR 4035
expected output
ERROR 4035 (HY000): Sequence 's' has run out
Fix
Add CYCLE or extend MAXVALUE
WHEN Values can wrap around or the range needs extending.
-- Allow cycling (reuse values from MINVALUE after exhaustion): ALTER SEQUENCE s CYCLE; -- Or extend the range: ALTER SEQUENCE s MAXVALUE 1000000;
Why this works
CYCLE causes the sequence to restart from MINVALUE after reaching MAXVALUE. Extending MAXVALUE avoids the exhaustion entirely.
✕ Use CYCLE on sequences that generate primary key values
Cycling a sequence used for primary keys will produce values that already exist, causing duplicate key errors (1062) unless old rows have been deleted.
SEQUENCE objects are a MariaDB 10.3+ feature. They are not available in MySQL.
MariaDB — CREATE SEQUENCE
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev