Adds a primary key out of an existing column or set of columns.
Name | Description |
---|---|
catalogName | Name of the catalog@ v3.0E.g. 'cat' |
clustered | boolean |
columnNames | Name of the column(s) to create the primary key on. Comma separated if multipleE.g. 'id, name' |
constraintName | Name of primary key constraintE.g. 'pk_person' |
forIndexCatalogName | |
forIndexName | E.g. 'A String'Supported by: db2, db2z, oracle |
forIndexSchemaName | |
schemaName | Name of the schemaE.g. 'public' |
tableName | Name of the table to create the primary key onE.g. 'person' |
tablespace | E.g. 'A String' |
validate | booleanThis is true if the primary key has 'ENABLE VALIDATE' set, or false if the primary key has 'ENABLE NOVALIDATE' set. |
<changeSet author="liquibase-docs" id="addPrimaryKey-example">
<addPrimaryKey catalogName="cat"
clustered="true"
columnNames="id, name"
constraintName="pk_person"
forIndexName="A String"
schemaName="public"
tableName="person"
tablespace="A String"
validate="true"/>
</changeSet>
changeSet:
id: addPrimaryKey-example
author: liquibase-docs
changes:
- addPrimaryKey:
catalogName: cat
clustered: true
columnNames: id, name
constraintName: pk_person
forIndexName: A String
schemaName: public
tableName: person
tablespace: A String
validate: true
{
"changeSet": {
"id": "addPrimaryKey-example",
"author": "liquibase-docs",
"changes": [
{
"addPrimaryKey": {
"catalogName": "cat",
"clustered": true,
"columnNames": "id, name",
"constraintName": "pk_person",
"forIndexName": "A String",
"schemaName": "public",
"tableName": "person",
"tablespace": "A String",
"validate": true
}
}]
}
}
ALTER TABLE cat.person ADD PRIMARY KEY (id,
name);
Database | Notes | Auto Rollback |
---|---|---|
DB2/LUW | Supported | Yes |
DB2/z | Supported | Yes |
Derby | Supported | Yes |
Firebird | Supported | Yes |
H2 | Supported | Yes |
HyperSQL | Supported | Yes |
INGRES | Supported | Yes |
Informix | Supported | Yes |
MariaDB | Supported | Yes |
MySQL | Supported | Yes |
Oracle | Supported | Yes |
PostgreSQL | Supported | Yes |
SQL Server | Supported | Yes |
SQLite | Not Supported | Yes |
Sybase | Supported | Yes |
Sybase Anywhere | Supported | Yes |