• Data Warehouse Service

dws
  1. Help Center
  2. Data Warehouse Service
  3. Developer Guide
  4. SQL Reference
  5. SQL Syntax
  6. ALTER SEQUENCE

ALTER SEQUENCE

Function

ALTER SEQUENCE modifies the parameters of an existing sequence.

You must be the owner of the sequence to use ALTER SEQUENCE.

NOTE:

In the current version, you can modify only the owner and home column. To modify other parameters, delete the sequence and create it again. Then, use the Setval function to restore original parameter values.

Precautions

None

Syntax

Change the owning column of a sequence.

ALTER SEQUENCE [ IF EXISTS ] name 
    [ OWNED BY { table_name.column_name | NONE } ] ;

Change the owner of a sequence.

ALTER SEQUENCE [ IF EXISTS ] name OWNER TO new_owner;

Parameter Description

  • name

    Specifies the sequence name to be changed.

  • IF EXISTS

    Sends a notification instead of an error when you are modifying a non-existing sequence.

  • OWNED BY

    Associates a sequence with a specified column included in a table. In this way, the sequence will be deleted when you delete its associated field or the table where the field belongs.

    If the sequence has been associated with another table before you use this parameter, the new association will overwrite the old one.

    The associated table and sequence must be owned by the same user and in the same schema.

    If OWNED BY NONE is used, existing associations will be deleted.

  • new_owner

    Specifies the user name of the new owner. To change the owner, you must also be a direct or indirect member of the new role, and this role must have CREATE permission on the sequence's schema.

Examples

-- Create a sequence named serial that starts from 101 and increases in ascending order:
CREATE SEQUENCE serial START 101;

-- Create a table, and specify default values for the sequence:
CREATE TABLE T1(C1 bigint default nextval('serial'));

-- Change the owning column of the serial sequence to T1.C1:
ALTER SEQUENCE serial OWNED BY T1.C1;

-- Delete the sequence.
DROP SEQUENCE serial cascade;
DROP TABLE T1;