# Use more than one key as incremental unique\_key

**URL:** <https://discourse.getdbt.com/t/use-more-than-one-key-as-incremental-unique-key/28>\
**Category:** Help\
**Tags:** incremental\
**Created:** [April 26, 2018, 7:33pm UTC](https://discourse.getdbt.com/t/use-more-than-one-key-as-incremental-unique-key/28 "2018-04-26T19:33:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicor88](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/nicor88/32/18_2.png) [@nicor88](https://discourse.getdbt.com/u/nicor88)\
**Post date:** [April 26, 2018, 7:33pm UTC](https://discourse.getdbt.com/t/use-more-than-one-key-as-incremental-unique-key/28/1 "2018-04-26T19:33:17Z")

</div>

Can I use multiple keys as unique\_key in config?  
e.g. Something like this: `unique_key = ['date_sk', 'campaign_id', 'message_type', 'variation_name']`

---

<div class="post-metadata">

**Author:** ![tristan](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/tristan/32/15_2.png) [@tristan](https://discourse.getdbt.com/u/tristan)\
**Post date:** [April 26, 2018, 7:58pm UTC](https://discourse.getdbt.com/t/use-more-than-one-key-as-incremental-unique-key/28/2 "2018-04-26T19:58:24Z")

</div>

Hey @nicor88! Great question. `unique_key` accepts any valid SQL. So, you could do:

```auto
unique_key = 'field_1 || field_2 || field_3'

```

…or something similar. Generally, what we recommend is for all models to include a unique key in the contents of the model itself. This helps with uniqueness testing so that you can avoid fanout errors in your SQL. If there is no natural key in the underlying data and you need to create a surrogate key, I’d recommend using the [surrogate key macro](https://github.com/fishtown-analytics/dbt-utils/blob/master/macros/sql/surrogate_key.sql) in dbt-utils to create one. Then you can easily pass that field into the `unique_key` config.

---

<div class="post-metadata">

**Author:** ![joellabes](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/joellabes/32/3980_2.png) [@joellabes](https://discourse.getdbt.com/u/joellabes)\
**Post date:** [September 9, 2022, 4:09am UTC](https://discourse.getdbt.com/t/use-more-than-one-key-as-incremental-unique-key/28/5 "2022-09-09T04:09:11Z")

</div>

As of dbt Core 1.1, a list of column values is supported, exactly in the way you described 🎉

See the docs for more info: [Configuring incremental models | dbt Docs](https://docs.getdbt.com/docs/building-a-dbt-project/building-models/configuring-incremental-models#defining-a-uniqueness-constraint-optional)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)\
**Post date:** [September 16, 2022, 4:10am UTC](https://discourse.getdbt.com/t/use-more-than-one-key-as-incremental-unique-key/28/6 "2022-09-16T04:10:04Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
