CREATE SEQUENCE
Creates a SEQUENCE
(GENERATOR
)
DSQL, ESQL
CREATE {SEQUENCE | GENERATOR} seq_name [START WITH start_value] [INCREMENT [BY] increment]
Parameter | Description |
---|---|
seq_name |
Sequence (generator) name.The maximum length is 63 characters |
start_value |
Initial value of the sequence.Default is 1. |
increment |
Increment of the sequence (when using |
The statements CREATE SEQUENCE
and CREATE GENERATOR
are synonymous — both create a new sequence.Either can be used, but CREATE SEQUENCE
is recommended as that is the syntax defined in the SQL standard.
When a sequence is created, its current value is set so that the next value obtained from NEXT VALUE FOR seq_name
is equal to start_value.In other words, the current value of the sequence is set to (start_value - increment
).By default, the start_value is 1 (one).
The optional INCREMENT [BY]
clause allows you to specify an increment for the NEXT VALUE FOR seq_name
expression.By default, the increment is 1 (one).The increment cannot be set to 0 (zero).The GEN_ID(seq_name, <step>)
function can be called instead, to “step” the series by a different integer number.The increment specified through INCREMENT [BY]
is not used for GEN_ID
.
Note
|
Non-standard behaviour for negative increments
The SQL standard specifies that sequences with a negative increment should start at the maximum value of the sequence (263 - 1) and count down.Firebird does not do that, and instead starts at This may change in a future Firebird version. |