Change: ‘addPrimaryKey’

Adds creates a primary key out of an existing column or set of columns.

Available Attributes

NameDescriptionRequired ForSupportsSince
catalogNameName of the catalogall3.0
columnNamesName of the column(s) to create the primary key on. Comma separated if multipleallall
constraintNameName of primary key constraintall
schemaNameName of the schemaall
tableNameName of the table to create the primary key onallall
tablespaceall
<changeSet author="liquibase-docs" id="addPrimaryKey-example">
    <addPrimaryKey catalogName="cat"
            columnNames="id, name"
            constraintName="pk_person"
            schemaName="public"
            tableName="person"
            tablespace="A String"/>
</changeSet>
changeSet:
  id: addPrimaryKey-example
  author: liquibase-docs
  changes:
  - addPrimaryKey:
      catalogName: cat
      columnNames: id, name
      constraintName: pk_person
      schemaName: public
      tableName: person
      tablespace: A String
{
  "changeSet": {
    "id": "addPrimaryKey-example",
    "author": "liquibase-docs",
    "changes": [
      {
        "addPrimaryKey": {
          "catalogName": "cat",
          "columnNames": "id, name",
          "constraintName": "pk_person",
          "schemaName": "public",
          "tableName": "person",
          "tablespace": "A String"
        }
      }]
    
  }
}

SQL Generated From Above Sample (MySQL)

ALTER TABLE cat.person ADD PRIMARY KEY (id,
 name);

Database Support

DatabaseNotesAuto Rollback
DB2SupportedYes
DerbySupportedYes
FirebirdSupportedYes
H2SupportedYes
HyperSQLSupportedYes
InformixSupportedYes
MySQLSupportedYes
OracleSupportedYes
PostgreSQLSupportedYes
SQL ServerSupportedYes
SQLiteNot SupportedYes
SybaseSupportedYes
Sybase AnywhereSupportedYes

Missing, incomplete or wrong information? Please send a pull request