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

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 privilege on the sequence and the CREATE privilege on the new schema.
  • To rename a sequence with ALTER SEQUENCE ... RENAME TO, the user must have the DROP privilege on the sequence and the CREATE privilege on the sequence’s database.

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 create a sequence that you would like to add to a new schema called cockroach_labs:
By default, unqualified sequences created in the database belong to the public schema:
If the new schema does not already exist, create it:
Then, change the sequence’s schema:

See also