# Snowflake dbt - How to use different role in model view?

**URL:** <https://discourse.getdbt.com/t/snowflake-dbt-how-to-use-different-role-in-model-view/8156>\
**Category:** Help\
**Created:** [May 4, 2023, 9:55pm UTC](https://discourse.getdbt.com/t/snowflake-dbt-how-to-use-different-role-in-model-view/8156 "2023-05-04T21:55:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jskprmr](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/jskprmr/32/2354_2.png) [@jskprmr](https://discourse.getdbt.com/u/jskprmr)\
**Post date:** [May 4, 2023, 9:55pm UTC](https://discourse.getdbt.com/t/snowflake-dbt-how-to-use-different-role-in-model-view/8156/1 "2023-05-04T21:55:34Z")

</div>

## The problem I’m having

I have Snowflake connection and building model.

## The context of why I’m trying to do this

Profile.yml is configured with ROLE\_1. When I create model view from dbt, the FROM clause having table with ROLE\_2. I have not configured ROLE\_2 anywhere and not sure where to configure.

When I compile the view from the model, it says schema does not exist because ROLE\_2 has this schema.

Can someone please help how do I configure ROLE\_2 so that my modeled view can be created in the ROLE\_! but using the ROLE\_2 schema table.

Please help.

## What I’ve already tried

## Some example code or error messages

```auto
Put code inside backticks
  to preserve indentation
    which is especially important 
      for Python and YAML! 

```

---

<div class="post-metadata">

**Author:** ![Surya](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/surya/32/3763_2.png) [@Surya](https://discourse.getdbt.com/u/Surya)\
**Post date:** [May 5, 2023, 4:53am UTC](https://discourse.getdbt.com/t/snowflake-dbt-how-to-use-different-role-in-model-view/8156/2 "2023-05-05T04:53:37Z")

</div>

I think there is no such feature as of now.  
It’s better to create a role for dbt and the role should have create object permissions on the databases ur using to create objects and read access on the sources db’s you are using in dbt.  
For more information

> **[Snowflake Permissions | dbt Developer Hub](https://docs.getdbt.com/reference/snowflake-permissions)**
>
> Example Snowflake permissions

---

<div class="post-metadata">

**Author:** ![jskprmr](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/jskprmr/32/2354_2.png) [@jskprmr](https://discourse.getdbt.com/u/jskprmr)\
**Post date:** [May 5, 2023, 9:17pm UTC](https://discourse.getdbt.com/t/snowflake-dbt-how-to-use-different-role-in-model-view/8156/3 "2023-05-05T21:17:00Z")

</div>

Thanks Surya for reply. View should be created in the DB\_CREATE database and the view is refering to DB\_READ database. Both this DB’s are residing in different roles. What are you suggesting here is to create dbt specific role on both these database so that dbt specific role will have permission on both the roles and this way we can use DB\_READ to create view in DB\_CREATE. Is this understanding correct?

If so, I have question on how can I at run-time inform dbt to read from DB\_READ but create view into DB\_CREATE. I have used pre-hook in dbt\_project.ym file to reference like below

models:  
+pre-hook: “USE ROLE DB\_READ\_DBT\_ROLE”

And in project.yml file, I have reference to DB\_CREATE\_DBT\_ROLE to create view in the DB\_READ.

NotE: I have tried config option in individual view .sql in model like below as well but no success.

{{  
config(  
pre\_hook=“USE ROLE DB\_READ\_DBT\_ROLE”  
)  
}}

Above is not working though and it always gives error DB\_WRITE database not found! Any idea and instruction to solve this issue? Thanks well in advance!
