createSequence

Creates a new sequence in Snowflake. Sequences generate unique numeric values and are commonly used for auto-incrementing primary keys.

Note: Automatic rollback drops the sequence.

Known limitation: This change type does not support database inspection features (snapshot, diff, diff-changelog, and generate-changelog commands).

Available attributes

Attribute

Type

Description

Required

catalogName

String

Name of the catalog (database) where the sequence is created

No

schemaName

String

Name of the schema where the sequence is created

No

sequenceName

String

Name of the sequence to create

Yes

orReplace

Boolean

Replace the sequence if it exists using OR REPLACE*

No

ifNotExists

Boolean

Only create if the sequence doesn't exist using IF NOT EXISTS*

No

startValue

Long

Initial value for the sequence

No

incrementBy

Long

Value to increment by for each sequence value

No

ordered

Boolean

Guarantee ordered sequence values (true for ORDER)

No

comment

String

Comment describing the sequence

No

* orReplace and ifNotExists are mutually exclusive.

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
  xmlns:pro-snowflake="http://www.liquibase.org/xml/ns/pro-snowflake"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
        http://www.liquibase.org/xml/ns/pro-snowflake
        http://www.liquibase.org/xml/ns/pro-snowflake/liquibase-pro-snowflake-latest.xsd">
  <!-- Basic sequence creation -->
  <changeSet id="create-sequence" author="examples">
    <pro-snowflake:createSequence sequenceName="ORDER_ID_SEQ"/>
  </changeSet>
  <!-- Sequence with IF NOT EXISTS -->
  <changeSet id="create-sequence-if-not-exists" author="examples">
    <pro-snowflake:createSequence
                sequenceName="CUSTOMER_ID_SEQ"
                ifNotExists="true"
                startValue="1000"
                incrementBy="1"/>
  </changeSet>
  <!-- Full-featured sequence -->
  <changeSet id="create-full-sequence" author="examples">
    <pro-snowflake:createSequence
                sequenceName="INVOICE_NUMBER_SEQ"
                startValue="100"
                incrementBy="5"
                ordered="true"
                comment="Generates unique invoice numbers"/>
  </changeSet>
</databaseChangeLog>