How to Add a Foreign Key
- Click Add Constraint +
- Select Add Foreign Key
- Select the target table
- Map local column(s) to referenced column(s)
- (Optional) Configure additional options
- SQL statement for creating Index is generated automatically
Target Table
Select the table that contains the referenced column(s). Must have a primary key or unique constraint
Columns
Define the relationship between columns.
- Select local column(s)
- Map them to referenced column(s) in the target table
- Single column - simple foreign key
- Multiple columns - composite foreign key (order must match)
On Delete
Defines what happens when a referenced row is deleted. Supported options may vary by database.
On Update
Defines what happens when referenced values are updated. Supported options may vary by database.
Options
Deferrable
Allows the constraint to be checked at transaction end instead of immediately. Supported only in some databases (e.g., PostgreSQL)
Initially Deferred
Only available if Deferrable is enabled. Constraint is checked at commit time by default. Supported only in some databases (e.g., PostgreSQL)