What would you like to know more about?

Primary & Foreign Keys

When records in two or more tables are related, key columns in each table are used to represent the relationship.

Primary Keys
Each table has a special column which serves to identify each record by using a unique value. In MinistryPlatform, Primary Keys are implemented as integers which automatically increment. These are the first column and are named after the table with "_ID" appended. In the Contacts/Contact Statuses example below, the Primary Key for Contacts is Contact_ID and the Primary Key for Contact_Statuses is Contact_Status_ID.
Foreign Keys
A Foreign Key is a column in a table which refers to the Primary Key in another (foreign) table.

For Example: Contact/Contact Statuses

Here is a simple example of two related records. If Contact_Statuses stores a value of 1 for "Active" status in the Primary Key column Contact_Status_ID, then a Contact record can refer to that status by storing the same value in a Foreign Key column named Contact_Status_ID. These are commonly named the same in both tables.