addForeignKeyConstraint

Adds a foreign key constraint to an existing column.

Available attributes

Name Description Required for Supports
baseColumnNames Name of the column(s) to place the foreign key constraint on. Comma-separate if multiple all all
baseTableCatalogName Name of the catalog of the base table all
baseTableName Name of the table containing the column to constraint all all
baseTableSchemaName Name of the schema of the base table all
constraintName

Name of the constraint

all all
deferrable

Defines whether constraints are deferrable

oracle, postgresql, sqlite
initiallyDeferred

Defines whether constraints are initially deferred

oracle, postgresql, sqlite
onDelete

ON DELETE functionality. Possible values: CASCADE, SET NULL, SET DEFAULT, RESTRICT, NO ACTION. Note that db2z only supports CASCADE, SET NULL, and RESTRICT

asany, db2, db2z, derby, firebird, h2, hsqldb, informix, ingres, mariadb, mssql, mysql, oracle, postgresql
onUpdate

ON UPDATE functionality. Possible values: CASCADE, SET NULL, SET DEFAULT, RESTRICT, NO ACTION

all except db2z
referencedColumnNames Name of the column(s) the foreign key points to. Comma-separate if multiple all all
referencedTableCatalogName Name of the catalog of the referenced table all
referencedTableName Name of the table the foreign key points to all all
referencedTableSchemaName Name of the schema of the referenced table all
validate

Set to true if the constraint has ENABLE VALIDATE set, or false if the constraint has ENABLE NOVALIDATE set.

all
referencesUniqueColumn

[Deprecated] Boolean.

all

Database support

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
Snowflake Supported Yes
SQL Server Supported Yes
SQLite Not Supported No
Sybase Supported Yes
Sybase Anywhere Supported Yes