Here are two examples of how to define a composite primary key for some table using Liquibase.
- Add the composite primary key up front during table construction (preferred).
<changeSet id="1">
<createTable tableName="some_table">
<column name="id_1" type="varchar_ignorecase">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_SOME_TABLE"></constraints>
</column>
<column name="id_2" type="varchar_ignorecase">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_SOME_TABLE"></constraints>
</column>
</createTable>
</changeSet>
- Add the composite primary key after the table has been created.
<changeSet id="2">
<addPrimaryKey columnNames="id_1, id_2"
constraintName="PK_SOME_TABLE"
tableName="some_table"
validate="true"/>
</changeSet>
Hi.
Maybe I'm late, but why is the first way preferred?
Thanks