Who Can Alter a Sequence?
The ALTER SEQUENCE
(ALTER GENERATOR
) statement can be executed by:
-
The owner of the sequence
-
Users with the
ALTER ANY SEQUENCE
(ALTER ANY GENERATOR
) privilege
The ALTER SEQUENCE
(ALTER GENERATOR
) statement can be executed by:
The owner of the sequence
Users with the ALTER ANY SEQUENCE
(ALTER ANY GENERATOR
) privilege
ALTER SEQUENCE
Setting the value of the EMP_NO_GEN
sequence so the next value is 145.
ALTER SEQUENCE EMP_NO_GEN RESTART WITH 145;
Resetting the base value of the sequence EMP_NO_GEN
to the initial value stored in the metadata
ALTER SEQUENCE EMP_NO_GEN RESTART;
Changing the increment of sequence EMP_NO_GEN
to 10
ALTER SEQUENCE EMP_NO_GEN INCREMENT BY 10;
CREATE OR ALTER SEQUENCE
Creates a sequence if it doesn’t exist, or alters a sequence
DSQL, ESQL
CREATE OR ALTER {SEQUENCE | GENERATOR} seq_name {RESTART | 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 |
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
CREATE OR ALTER SEQUENCE
EMP_NO_GEN
CREATE OR ALTER SEQUENCE EMP_NO_GEN
START WITH 10
INCREMENT BY 1
DROP SEQUENCE
Drops a SEQUENCE
(GENERATOR
)
DSQL, ESQL
DROP {SEQUENCE | GENERATOR} seq_name
Parameter | Description |
---|---|
seq_name |
Sequence (generator) name.The maximum length is 63 characters |
The statements DROP SEQUENCE
and DROP GENERATOR
statements are equivalent: both drop (delete) an existing sequence (generator).Either is valid but DROP SEQUENCE
, being defined in the SQL standard, is recommended.
The statements will fail if the sequence (generator) has dependencies.
The DROP SEQUENCE
(DROP GENERATOR
) statement can be executed by:
The owner of the sequence
Users with the DROP ANY SEQUENCE
(DROP ANY GENERATOR
) privilege
DROP SEQUENCE
EMP_NO_GEN
series:DROP SEQUENCE EMP_NO_GEN;
RECREATE SEQUENCE
Drops a sequence if it exists, and creates a sequence (generator)
DSQL, ESQL
RECREATE {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 |
increment |
Increment of the sequence (when using |
See [fblangref50-ddl-sequence-create] for the full syntax of CREATE SEQUENCE
and descriptions of defining a sequences and its options.
RECREATE SEQUENCE
creates or recreates a sequence.If a sequence with this name already exists, the RECREATE SEQUENCE
statement will try to drop it and create a new one.Existing dependencies will prevent the statement from executing.
RECREATE SEQUENCE
EMP_NO_GEN
RECREATE SEQUENCE EMP_NO_GEN
START WITH 10
INCREMENT BY 2;
SET GENERATOR
Sets the current value of a sequence (generator)
DSQL, ESQL
SET GENERATOR seq_name TO new_val
Parameter | Description |
---|---|
seq_name |
Generator (sequence) name |
new_val |
New sequence (generator) value.A 64-bit integer from -2-63 to 263-1. |
The SET GENERATOR
statement sets the current value of a sequence or generator to the specified value.
Note
|
Although |
SET GENERATOR
?The SET GENERATOR
statement can be executed by:
The owner of the sequence (generator)
Users with the ALTER ANY SEQUENCE
(ALTER ANY GENERATOR
) privilege
SET GENERATOR
EMP_NO_GEN
sequence to 145:SET GENERATOR EMP_NO_GEN TO 145;
Note
|
Similar effects can be achieved with [fblangref50-ddl-sequence-alter]: ALTER SEQUENCE EMP_NO_GEN RESTART WITH 145 + increment; Here, the value of increment is the current increment of the sequence.We need add it as |