Liquibase® version 3.8.5 is now available! Get it for free.
2018 XML Announcement
News All Previous Posts >>

Subscribe for email updates

- and/or -

Change: ‘addAutoIncrement’

Converts an existing column to be an auto-increment (a.k.a ‘identity’) column

Available Attributes

NameDescription
catalogNameName of the catalog@ v3.0E.g. 'cat'
columnDataTypeCurrent data type of the column to make auto-incrementRequired for: asany, h2, hsqldb, informix, ingres, mariadb, mysql, sybase, unsupportedE.g. 'int'
columnNameName of the columnE.g. 'id'
defaultOnNullbooleanWhen using generationType 'BY DEFAULT' then defaultOnNull = true allows the identity to be used if the identity column is referenced, but a value of NULL is specified.@ v3.6Supported by: oracle
generationTypeType of the generation in 'GENERATED %s AS IDENTITY'. ALWAYS | BY DEFAULT@ v3.6E.g. 'ALWAYS'
incrementByintegerThe value the increment incremented by each callE.g. '1'
schemaNameName of the schemaE.g. 'public'
startWithintegerInitial value of the incrementE.g. '100'
tableNameName of the tableE.g. 'person'
<changeSet author="liquibase-docs" id="addAutoIncrement-example">
    <addAutoIncrement catalogName="cat"
            columnDataType="int"
            columnName="id"
            defaultOnNull="false"
            generationType="ALWAYS"
            incrementBy="1"
            schemaName="public"
            startWith="100"
            tableName="person"/>
</changeSet>
changeSet:
  id: addAutoIncrement-example
  author: liquibase-docs
  changes:
  - addAutoIncrement:
      catalogName: cat
      columnDataType: int
      columnName: id
      defaultOnNull: false
      generationType: ALWAYS
      incrementBy: 1
      schemaName: public
      startWith: 100
      tableName: person
{
  "changeSet": {
    "id": "addAutoIncrement-example",
    "author": "liquibase-docs",
    "changes": [
      {
        "addAutoIncrement": {
          "catalogName": "cat",
          "columnDataType": "int",
          "columnName": "id",
          "defaultOnNull": false,
          "generationType": "ALWAYS",
          "incrementBy": 1,
          "schemaName": "public",
          "startWith": 100,
          "tableName": "person"
        }
      }]
    
  }
}

SQL Generated From Above Sample (MySQL)

ALTER TABLE cat.person MODIFY id INT AUTO_INCREMENT;

ALTER TABLE cat.person AUTO_INCREMENT=100;

Database Support

DatabaseNotesAuto Rollback
DB2/LUWSupportedNo
DB2/zSupportedNo
DerbyNot SupportedNo
FirebirdNot SupportedNo
H2SupportedNo
HyperSQLSupportedNo
INGRESSupportedNo
InformixSupportedNo
MariaDBSupportedNo
MySQLSupportedNo
OracleNot SupportedNo
PostgreSQLSupportedNo
SQL ServerNot SupportedNo
SQLiteSupported: If the column type is not INTEGER it is converted to INTEGERNo
SybaseSupportedNo
Sybase AnywhereSupportedNo