Skip to main content
The ALTER SEQUENCE applies a to a sequence.
The “ statement performs a schema change. For more information about how online schema changes work in CockroachDB, see .

Required privileges

  • To alter a sequence, the user must be the owner of the sequence.
  • To change the schema of a sequence with ALTER SEQUENCE ... SET SCHEMA, the user must have the DROP on the sequence and the CREATE privilege on the new schema.
  • New in v26.3: To rename a sequence with ALTER SEQUENCE ... RENAME TO, the user must have the DROP on the sequence and the CREATE privilege on the sequence’s schema.

Syntax

alter_sequence syntax diagram

Parameters

Examples

Change the increment value of a sequence

In this example, we’re going to change the increment value of a sequence from its current state (i.e., 1) to 2.

Rename a sequence

In this example, we will change the name of sequence.

Change the schema of a sequence

Suppose you that you would like to add to a new schema called cockroach_labs:
By default, created in the database belong to the public schema:
If the new schema does not already exist, :
Then, change the sequence’s schema:

Known limitations

  • Altering the minimum or maximum value of a series does not check the current value of a series. This means that it is possible to silently set the maximum to a value less than, or a minimum value greater than, the current value.

See also