addAutoIncrement
Converts an existing column to be an auto-increment (a.k.a 'identity') column.
Run addAutoIncrement
To run this Change Type, follow these steps:
- Add the Change Type to your changeset, as shown in the examples on this page.
- Specify any required attributes. Use the table on this page to see which ones your database requires.
- Deploy your changeset by running the
update
command:
liquibase update
Available attributes
Attribute | Description | Required for | Supports |
---|---|---|---|
catalogName
|
Name of the catalog |
-- | all |
columnDataType
|
Data type of the column. To help make scripts database-independent, Liquibase automatically converts the following generic data types to the correct database implementation: Also, specifying a
For Snowflake, Liquibase also implements For Databricks, Liquibase also implements Note: To specify a complex Databricks type like For more information, see Liquibase Data Type Handling. |
asany, h2, hsqldb, informix, ingres, mariadb, mysql, sybase, unsupported | all |
columnName
|
Name of the column |
all | all |
defaultOnNull
|
When using |
-- | oracle |
generationType
|
Type of the generation in |
-- | all |
incrementBy
|
Integer amount to increment by at each call |
-- | all |
schemaName
|
Name of the schema |
-- | all |
startWith
|
Initial integer value of the increment |
-- | all |
tableName
|
Name of the table |
all | all |
Examples
SQL example
--liquibase formatted sql
--changeset liquibase-docs:addAutoIncrement-example
ALTER TABLE cat.person MODIFY id INT AUTO_INCREMENT;
ALTER TABLE cat.person AUTO_INCREMENT=100;
Database support
Database | Notes | Auto Rollback |
---|---|---|
DB2/LUW | Supported | No |
DB2/z | Not Supported | No |
Derby | Not Supported | No |
Firebird | Not Supported | No |
Google BigQuery | Supported | No |
H2 | Supported | No |
HyperSQL | Supported | No |
INGRES | Supported | No |
Informix | Supported | No |
MariaDB | Supported | No |
MySQL | Supported | No |
Oracle | Not Supported | No |
PostgreSQL | Supported | No |
Snowflake | Not Supported | No |
SQL Server | Not Supported | No |
SQLite | Supported: If the column type is not INTEGER it is converted to INTEGER | No |
Sybase | Supported | No |
Sybase Anywhere | Supported | No |