---
updatedAt: 2026-05-04T21:16:02.000Z
agentTools:
  projectIndex: https://docs.observeinc.com/llms.txt
---

# set_link

Aliases: `addfk` (deprecated).

```
set_link [^label]?, [keyfield: col storable]+
```

Declares a foreign key from the current dataset to another bound dataset or stage so resources can be resolved through the specified column mapping.

The first argument may be omitted, or it may be a literal string or link reference giving the link’s label; when omitted, the label defaults from the target’s type name, stage id, or dataset reference as available. Each remaining argument maps a source column (optionally with an object path for nested fields) to a single target column using `@TargetName.column` syntax; array indices in paths are not allowed. All mappings must target the same dataset. Source and target column types must be comparable when the compiler can see the target schema. The destination column set must identify a candidate key or the primary key on the target; if the combination is a key but not yet declared, add it with [add\_key](verb-add_key) on the target definition first. The output schema matches the input columns while appending foreign-key metadata; execution does not rewrite row payloads for this step. See also [lookup](verb-lookup) and [join](verb-join) for using declared links in queries.

# Categories

* [Metadata](verb#metadata-verbs)

# Accelerable

set\_link is always accelerable if the input is accelerable. A dataset that only uses accelerable verbs can be accelerated, making
queries on the dataset respond faster.

# Examples

<OpalCodeBlock code={
`set_link "Month ref", month_number:@months.month_number
`}/>

Declares a labeled foreign key from this dataset’s `month_number` column to the `month_number` column on the bound `@months` target.

<OpalCodeBlock code={
`set_primary_key month_number
set_link month_number:@months.month_number
`}/>

Adds an unlabeled foreign key to `@months` using the default link naming rules while matching `month_number` on both sides.

<OpalCodeBlock code={
`set_primary_key month_number
set_link @month_fk, month_number:@months.month_number
`}/>

Uses a link reference for the foreign-key label instead of a string literal, while still mapping `month_number` to the same column on `@months`.