FirebirdSQL logo
 FILTEREXCEPTION 

CREATE OR ALTER SEQUENCE

Creates a sequence if it doesn’t exist, or alters a sequence

Available in

DSQL, ESQL

Syntax
CREATE OR ALTER {SEQUENCE | GENERATOR} seq_name
  {RESTART | START WITH start_value}
  [INCREMENT [BY] increment]
Table 1. CREATE OR ALTER SEQUENCE Statement Parameters
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 NEXT VALUE FOR seq_name);cannot be 0.Default is 1.

If the sequence does not exist, it will be created.An existing sequence will be changed:

  • If RESTART is specified, the sequence will restart with the initial value stored in the metadata

  • If the START WITH clause is specified, the sequence is restarted with start_value, but the start_value is not stored.In other words, it behaves as RESTART WITH in [fblangref50-ddl-sequence-alter].

  • If the INCREMENT [BY] clause is specified, increment is stored as the increment in the metadata, and used for subsequent calls to NEXT VALUE FOR

Example of CREATE OR ALTER SEQUENCE

Create a new or modify an existing sequence EMP_NO_GEN
CREATE OR ALTER SEQUENCE EMP_NO_GEN
  START WITH 10
  INCREMENT BY 1