# foreignKey

fun foreignKey(vararg from: Column<*>, target: Table.PrimaryKey, onUpdate: ReferenceOption? = null, onDelete: ReferenceOption? = null, name: String? = null)

Creates a composite foreign key.

#### Parameters

from

Columns in this referencing child table that compose the foreign key. Their order should match the order of columns in the referenced parent table's primary key.

target

Primary key of the referenced parent table.

onUpdate

ReferenceOption when performing update operations.

onDelete

ReferenceOption when performing delete operations.

name

Custom foreign key constraint name.

#### Samples

org.jetbrains.exposed.sql.tests.shared.ddl.CreateMissingTablesAndColumnsTests.CompositeForeignKeyTable

fun foreignKey(vararg references: Pair<Column<*>, Column<*>>, onUpdate: ReferenceOption? = null, onDelete: ReferenceOption? = null, name: String? = null)

Creates a composite foreign key.

#### Parameters

references

Pairs of child table and parent table columns that compose the foreign key. The first value of each pair should be a column from this referencing child table, with the second value being a column from the referenced parent table. All referencing columns must belong to this table. All referenced columns must belong to the same table.

onUpdate

ReferenceOption when performing update operations.

onDelete

ReferenceOption when performing delete operations.

name

Custom foreign key constraint name.

#### Samples

org.jetbrains.exposed.sql.tests.shared.DDLTests.testCompositeFKReferencingUniqueIndex