A sequence is a database object that generates numeric values according to configured rules such as starting value and increment. Unlike an identity column, a sequence can generally be used independently of a single table column.
Sequences provide flexible identifier generation and can be useful when multiple tables or processes need controlled numeric values.
A sequence can generate unique reference numbers for transactions before the transaction record is inserted.
CREATE SEQUENCE OrderSequence
START WITH 1000
INCREMENT BY 1;
Sequences are useful for transaction identifiers, invoice numbers, reference numbers, and systems requiring controlled numeric generation.
- A sequence generates numeric values.
- It can be configured with a starting value.
- Its increment can be configured.
- It can be independent of a table.
- Sequence syntax varies across database systems.
What is a SQL sequence?
A sequence is a database object that generates a series of numeric values according to configured rules.
How is a sequence different from an identity column?
A sequence is generally an independent database object, while an identity column is associated directly with a table column.