Creates a lookup table containing values stored in a column and creates a foreign key to the new table.
| Name | Description |
|---|---|
| constraintName | Name of the foreign-key constraint to create between the existing table and the lookup tableE.g. 'fk_address_state' |
| existingColumnName | Name of the column containing the data to extractE.g. 'state' |
| existingTableCatalogName | |
| existingTableName | Name of the table containing the data to extractE.g. 'address' |
| existingTableSchemaName | |
| newColumnDataType | Data type of the new table columnE.g. 'char(2)'Required for: informix, mariadb, mssql, mysql |
| newColumnName | Name of the column in the new table to createE.g. 'abbreviation' |
| newTableCatalogName | @ v3.0E.g. 'cat' |
| newTableName | Name of lookup table to createE.g. 'state' |
| newTableSchemaName | E.g. 'public' |
<changeSet author="liquibase-docs" id="addLookupTable-example">
<addLookupTable constraintName="fk_address_state"
existingColumnName="state"
existingTableName="address"
newColumnDataType="char(2)"
newColumnName="abbreviation"
newTableCatalogName="cat"
newTableName="state"
newTableSchemaName="public"/>
</changeSet>changeSet:
id: addLookupTable-example
author: liquibase-docs
changes:
- addLookupTable:
constraintName: fk_address_state
existingColumnName: state
existingTableName: address
newColumnDataType: char(2)
newColumnName: abbreviation
newTableCatalogName: cat
newTableName: state
newTableSchemaName: public{
"changeSet": {
"id": "addLookupTable-example",
"author": "liquibase-docs",
"changes": [
{
"addLookupTable": {
"constraintName": "fk_address_state",
"existingColumnName": "state",
"existingTableName": "address",
"newColumnDataType": "char(2)",
"newColumnName": "abbreviation",
"newTableCatalogName": "cat",
"newTableName": "state",
"newTableSchemaName": "public"
}
}]
}
}CREATE TABLE cat.state AS SELECT DISTINCT state AS abbreviation FROM address WHERE state IS NOT NULL;
ALTER TABLE public.state MODIFY abbreviation CHAR(2) NOT NULL;
ALTER TABLE public.state ADD PRIMARY KEY (abbreviation);
ALTER TABLE address ADD CONSTRAINT fk_address_state FOREIGN KEY (state) REFERENCES public.state (abbreviation);| Database | Notes | Auto Rollback |
|---|---|---|
| DB2/LUW | Supported | Yes |
| DB2/z | Supported | Yes |
| Derby | Supported | Yes |
| Firebird | Not Supported | Yes |
| H2 | Supported | Yes |
| HyperSQL | Not 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 |