# Add constraints and descriptions to table

**URL:** <https://discourse.getdbt.com/t/add-constraints-and-descriptions-to-table/2175>\
**Category:** Archive\
**Created:** [February 24, 2021, 2:19pm UTC](https://discourse.getdbt.com/t/add-constraints-and-descriptions-to-table/2175 "2021-02-24T14:19:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hazal](https://avatars.discourse-cdn.com/v4/letter/h/73ab20/32.png) [@Hazal](https://discourse.getdbt.com/u/Hazal)\
**Post date:** [February 24, 2021, 2:19pm UTC](https://discourse.getdbt.com/t/add-constraints-and-descriptions-to-table/2175/1 "2021-02-24T14:19:42Z")

</div>

Hi,  
I am a new user of dbt. If you could assist me on some doubts I will be so appreciated.  
I need to define constraints at table, but I could not find any way to do it through dbt. I would like to do something like below:  
ALTER TABLE dim\_customers  
ADD CONSTRAINT PK\_customer\_id PRIMARY KEY (‘company\_id’, ‘customer\_id’)

Alter table function does not work for dbt. This should be done in config block, right?  
If I define them in yml file, it does not appear as primary key at dim\_customers table in Snowflake. It only is mentioned at documentation.  
Like below:  
columns:  
- name: company\_id  
config:  
primary\_key: true  
description: The primary.

Also I need to see descriptions of the columns at the table in Snowflake. Once I add descriptions in yml file they only appear in documentation, but they do not appear at the table in Snowflake likewise primary key.

Could you please support me in this?  
Thanks,  
Regards  
Hazal

---

<div class="post-metadata">

**Author:** ![meurant.naude](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/meurant.naude/32/506_2.png) [@meurant.naude](https://discourse.getdbt.com/u/meurant.naude)\
**Post date:** [February 24, 2021, 7:09pm UTC](https://discourse.getdbt.com/t/add-constraints-and-descriptions-to-table/2175/2 "2021-02-24T19:09:26Z")

</div>

Hi there Hazal,  
To ensure description appear, add `persist_docs = {"relation": true, 'columns': true}` to the config block.  
Or have a read of the [documentation](https://docs.getdbt.com/reference/resource-configs/persist_docs).

Can’t help with the Snowflake primary key question, I’m not familiar with Snowflake.  
Cheers,  
Meurant

---

<div class="post-metadata">

**Author:** ![Hazal](https://avatars.discourse-cdn.com/v4/letter/h/73ab20/32.png) [@Hazal](https://discourse.getdbt.com/u/Hazal)\
**Post date:** [February 25, 2021, 10:25am UTC](https://discourse.getdbt.com/t/add-constraints-and-descriptions-to-table/2175/3 "2021-02-25T10:25:02Z")

</div>

Hi Meurant,

It works very well.

Many thanks for your assistance.  
Hazal

---

<div class="post-metadata">

**Author:** ![Hazal](https://avatars.discourse-cdn.com/v4/letter/h/73ab20/32.png) [@Hazal](https://discourse.getdbt.com/u/Hazal)\
**Post date:** [February 26, 2021, 10:57am UTC](https://discourse.getdbt.com/t/add-constraints-and-descriptions-to-table/2175/4 "2021-02-26T10:57:04Z")

</div>

Hi dear dbt users,  
Can anybody help on adding constraints a table in Snowflake through dbt please? DBT doesn’t recognize constraints mention and Snowflake doesn’t use indexes.  
How do you add constraints to your Snowflake table?  
Thanks in advance,  
Regards  
Hazal

---

<div class="post-metadata">

**Author:** ![kkrause](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/kkrause/32/585_2.png) [@kkrause](https://discourse.getdbt.com/u/kkrause)\
**Post date:** [March 3, 2021, 4:52pm UTC](https://discourse.getdbt.com/t/add-constraints-and-descriptions-to-table/2175/5 "2021-03-03T16:52:38Z")

</div>

Hi Hazel - you can take a look at hooks and operations. [link](https://docs.getdbt.com/docs/building-a-dbt-project/hooks-operations)
