JetBrains Rider
 
Get JetBrains Rider
Get your hands on the new features ahead of the release by joining the Early Access Program for Rider 2025.1! Learn more

Foreign keys

Last modified: 15 May 2024

Foreign key relationships specify how tables relate to each other and indicate relationships between tables. JetBrains Rider recognizes foreign key relationships in your database schema and uses them to construct JOIN clauses. You can see these relationships in the auto-completion list, data navigation, and diagrams.

In JetBrains Rider, you can use explicit foreign keys or create virtual foreign keys.

Foreign keys ( Foreign Key) can be found in the Database tool window. For the reference on other node and object icons, refer to the Data sources and their elements chapter of Database window topic. For the table column icons, refer to the Possible icon combinations for columns chapter.

Foreign keys in Database

A foreign key is a field or a collection of fields in one table that refers to the primary key in another table. When you create or modify a table, you can clearly define those keys:

The table that contains a foreign key is a child table. The table that contains a candidate key is a referenced or target table. If your database contains explicit foreign key relationships, JetBrains Rider automatically uses them in auto-completion, data navigation, and diagrams.

In the following example, activity.activity_id is a primary key, while visitor.activity_id is a foreign key.

Explicit foreign keys