> For the complete documentation index, see [llms.txt](https://docs.whalesync.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.whalesync.com/connectors/google-sheets/foreign-keys.md).

# Foreign keys

Set up foreign keys in Google Sheets with a Related\_\[Table Name] column holding Whalesync IDs, mapped to linked records or reference fields in other apps.

Foreign keys allow you to create relationships between tables in your synced Google Sheets.

<figure><img src="https://2481481593-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtLaMDbvbGOow76E8CnqW%2Fuploads%2Fgit-blob-0ec453c61a707f166b0ccd8223ddff4ad5d150e5%2FSheets.png?alt=media" 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%2Fgit-blob-79163d21b73e2a17eb0b8c9d12b1a868a239d642%2FRelated%20People.png?alt=media" 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.
{% endhint %}

#### 2. Map the Foreign Key field in Whalesync

<figure><img src="https://2481481593-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtLaMDbvbGOow76E8CnqW%2Fuploads%2Fgit-blob-0cb18d47e166034856ca6d9ed18493291f505622%2FMap%20fields.png?alt=media" alt=""><figcaption></figcaption></figure>

Google Sheets foreign key fields map with [reference fields](/features/additional-features/reference-fields.md) in other apps.

{% hint style="info" %}
You will likely need to click "Refresh" 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:

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%2Fgit-blob-0d348175e250accbf3137b5c84d4e316cc2150d3%2Fvalues.gif?alt=media" 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.**
{% endhint %}
