ALTER SEQUENCE

更新时间:
复制 MD 格式

This topic describes how to modify the start value of a sequence or change its type. This operation does not apply to group sequences that have more than one unit.

Usage notes

When you change a sequence type, note the following:

  • A group sequence that contains more than one unit cannot be converted to another type, and its unit-related parameters cannot be modified. Forcing a conversion may cause the sequence to malfunction.
  • Before changing the START WITHSTART WITH parameter, carefully evaluate existing sequence values and their generation rate to prevent conflicts. Change this value only when absolutely necessary.
  • The START WITH parameter is required when you use the ALTER SEQUENCE CHANGE TO statement to convert a sequence type. If the CHANGE TO clause is omitted, this parameter is optional.

New sequence

Syntax
ALTER SEQUENCE <name> [ CHANGE TO GROUP | TIME ]
START WITH <numeric value>
[ INCREMENT BY <numeric value> ]
[ MAXVALUE <numeric value> ]
[ CYCLE | NOCYCLE ]
Parameter Description
Parameter Description
START WITH The start value of the new sequence. If this parameter is not specified, the default value is 1.
INCREMENT BY Specifies the step size of the new sequence. Default: 1. This parameter applies only when modifying the properties of a new sequence, not when converting it to a group or time sequence.
MAXVALUE Specifies the maximum value for the new sequence, which must be a positive integer. Default: The maximum value of a signed BIGINT (9223372036854775807). This parameter applies only when modifying the properties of a new sequence, not when converting it to a group or time sequence.
CYCLE or NOCYCLE Specifies whether the sequence restarts from the start value after it reaches the maximum value.
  • CYCLE: The sequence restarts from its start value after reaching the maximum value.
  • NOCYCLE: Prevents the sequence from restarting. An error is returned if more values are requested after the maximum value is reached. NOCYCLE is the default.

This parameter applies only when modifying the properties of a new sequence, not when converting it to a group or time sequence.

Note
  • When you convert a sequence to a group sequence, only a single default unit is supported.
  • The start value has no effect when you convert a sequence to a time sequence.

Group sequence

Syntax
ALTER SEQUENCE <name> [ CHANGE TO NEW | TIME ]
START WITH <numeric value>
[ INCREMENT BY <numeric value> ]
[ MAXVALUE <numeric value> ]
[ CYCLE | NOCYCLE ]
Parameter Description
Parameter Description
START WITH The start value of the sequence. If this parameter is not specified, the default value is 1.
INCREMENT BY Specifies the step size. Default: 1. This parameter applies only when converting a group sequence to a new sequence.
MAXVALUE Specifies the maximum value for the sequence, which must be a positive integer. Default: The maximum value of a signed BIGINT (9223372036854775807). This parameter applies only when converting a group sequence to a new sequence.
CYCLE or NOCYCLE Specifies whether the sequence restarts from the start value. This parameter applies only when converting a group sequence to a new sequence.
  • CYCLE: The sequence restarts from its start value after it reaches the maximum value.
  • NOCYCLE: Prevents the sequence from restarting. An error is returned if more values are requested after the maximum value is reached. NOCYCLE is the default.
Note

When you convert a sequence to a time sequence, the start value, step size, maximum value, and CYCLE/NOCYCLE parameters are ignored.

Time sequence

Syntax
ALTER SEQUENCE <name> [ CHANGE TO NEW | GROUP ]
START WITH <numeric value>
[ INCREMENT BY <numeric value> ]
[ MAXVALUE <numeric value> ]
[ CYCLE | NOCYCLE ]
Parameter Description
Parameter Description
START WITH The start value of the sequence. If this parameter is not specified, the default value is 1.
INCREMENT BY Specifies the step size. Default: 1. This parameter applies only when converting a time sequence to a new sequence.
MAXVALUE Specifies the maximum value for the sequence, which must be a positive integer. Default: The maximum value of a signed BIGINT (9223372036854775807). This parameter applies only when converting a time sequence to a new sequence.
CYCLE or NOCYCLE Specifies whether the sequence restarts from the start value. This parameter applies only when converting a time sequence to a new sequence.
  • CYCLE: The sequence restarts from its start value after it reaches the maximum value.
  • NOCYCLE: Prevents the sequence from restarting. An error is returned if more values are requested after the maximum value is reached. NOCYCLE is the default.
Note When you convert a sequence to a group sequence, only a single default unit is supported. The start value, step size, maximum value, and CYCLE/NOCYCLE parameters are ignored.

Examples

  • To modify the start value of a sequence:
    ALTER SEQUENCE seq1 START WITH 1000000;
  • To convert a sequence to a group sequence:
    ALTER SEQUENCE seq2 CHANGE TO GROUP START WITH 2000000;
  • To convert a sequence to a time sequence:
    ALTER SEQUENCE seq3 CHANGE TO TIME;
  • To convert a sequence to a new sequence with default parameters:
    ALTER SEQUENCE seq4 CHANGE TO NEW START WITH 100;
  • To convert a sequence to a new sequence with custom parameters:
    ALTER SEQUENCE seq5 CHANGE TO NEW START WITH 200 INCREMENT BY 2 MAXVALUE 300 NOCYCLE;