Sequences
A sequence is a monotonic counter the engine maintains for ID generation. You rarely create one directly: declaring a column with { auto_increment } gives that column its own sequence, and the engine draws from it on every insert.
Auto-increment columns
Any integer column can auto-increment. Writers simply omit the column and each row receives the next value - no coordination, no SELECT MAX, no application-side counters. Run the snippets on this page in order:
Repositioning a sequence
The sequence behind a column is addressed as namespace::table::column. alter sequence ... set value N repositions it; the next insert draws N + 1. This is how imports preserve existing IDs and how ID ranges are carved out:
Reading generated IDs back
The row's generated ID is often needed immediately - to reference it, to return it to a client. returning hands it back from the insert itself, in the same statement:
