After a sequence is created, you can use the ALTER SEQUENCE statement to modify its attributes. OceanBase AI Database supports modifying the start value, minimum value, maximum value, increment step, and cycle attribute of a sequence.
The SQL syntax for modifying a sequence is as follows:
ALTER SEQUENCE [database_name.]sequence_name
{
[RESTART]
|[START WITH int_value]
|[MINVALUE int_value | NOMINVALUE]
|[MAXVALUE int_value | NOMAXVALUE]
|[INCREMENT BY int_value]
|[CACHE int_value | NOCACHE]
|[ORDER | NOORDER]
|[CYCLE | NOCYCLE]
};
To execute this statement, you must have the ALTER privilege.
Examples:
Modify the maximum value of the sequence
seq2and specify cyclic generation of sequence values.obclient> ALTER SEQUENCE seq2 MAXVALUE 1024 CYCLE;Modify the start value of a sequence.
If the value of
INCREMENT BYis greater than0, you can reset the sequence so that it starts fromMINVALUE. If the value ofINCREMENT BYis less than0, you can reset the sequence so that it starts fromMAXVALUE. The statements are as follows:obclient> ALTER SEQUENCE seq3 RESTART; Query OK, 0 rows affectedReset the sequence so that it starts from
3. The statement is as follows:obclient> ALTER SEQUENCE seq4 RESTART START WITH 3; Query OK, 0 rows affected
When you modify the start value of a sequence,
RESTARTdoes not have to be placed after the sequence name; it can be anywhere in the statement. Example:obclient> ALTER SEQUENCE seq4 START WITH 3 RESTART MINVALUE -100 CYCLE; Query OK, 0 rows affected
For more information about the ALTER SEQUENCE statement, see ALTER SEQUENCE.
References
For more sequence-related operations, see the following topics: