# Foreign keys

Foreign keys allow you to create relationships between tables in your synced Google Sheets.&#x20;

<figure><img src="https://2481481593-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtLaMDbvbGOow76E8CnqW%2Fuploads%2FE1984DAAZ5AQ5AyqvKMy%2FSheets.png?alt=media&#x26;token=52815a94-acfb-4b54-a8f1-bfab1adf78b7" alt=""><figcaption><p>An example of a foreign key field relating People to Tasks</p></figcaption></figure>

### How to set up foreign keys

#### 1. Define a foreign key column

Create a column in the following format: `Related_[Table Name]`

<figure><img src="https://2481481593-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtLaMDbvbGOow76E8CnqW%2Fuploads%2F4ixNAwcjXOjWJLFpdVRO%2FRelated%20People.png?alt=media&#x26;token=7feb4354-1c07-4851-b799-ab0c17a16b70" alt=""><figcaption><p>Here our column name is "Related_People" because we're relating Tasks to the People table</p></figcaption></figure>

{% hint style="info" %}
Capitalization matters, so make sure the table name matches exactly.&#x20;
{% endhint %}

#### 2. Map the Foreign Key field in Whalesync&#x20;

<figure><img src="https://2481481593-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtLaMDbvbGOow76E8CnqW%2Fuploads%2FS4RWaJxTyPXQn3okTOrM%2FMap%20fields.png?alt=media&#x26;token=2615085d-1ea7-4a40-a6d8-424a7de622c2" alt=""><figcaption></figcaption></figure>

Google Sheets foreign key fields map with [reference fields](https://docs.whalesync.com/features/additional-features/reference-fields) in other apps.

{% hint style="info" %}
You will likely need to click "Referesh" to ensure Whalesync sees your newest fields
{% endhint %}

#### 3. Insert Foreign Key values

To link a row from another table to your Foreign Key column:&#x20;

1. Copy the Whalesync ID of the row you want to reference.
2. Paste the Whalesync ID into the foreign key column.

<figure><img src="https://2481481593-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtLaMDbvbGOow76E8CnqW%2Fuploads%2FbvgFq3viEb7PV2It1kmE%2Fvalues.gif?alt=media&#x26;token=1c09fe53-4be8-4d52-90fa-f7de5fd1d06d" alt=""><figcaption><p>Copying the Whalesync ID from a person in the People's table into the "Related_People" column in Tasks</p></figcaption></figure>

* The Whalesync ID is a unique identifier for each row.
* It is Column A in each mapped table in Google Sheets, and it is hidden.
* Click on the arrow to unhide the Whalesync ID column.

{% hint style="warning" %}
**Avoid making any changes to the Whalesync ID column to avoid sync issues.**&#x20;
{% endhint %}
