Module 17 · Lesson 3 of 12Detailed study · about 25 min

Snowflake Account Roles vs. Database Roles: Grants and Inheritance

Bundle report access inside one database, then grant the database role to an account role that users can activate and that can use a warehouse.

Give the database owner a reusable permission bundle

Maple Market wants reporting teams to reuse the same approved data permissions in M17_ACCESS_LAB. A database role is defined inside one database and can hold privileges on that database and its objects. An account role can hold warehouse privileges and privileges from multiple databases. The user activates an account role to run the query.

The database role REPORT_READER carries access to the reporting schema and its table. M17_ANALYST is an account role granted REPORT_READER. M17_ANALYST also gets warehouse USAGE from the warehouse owner. Ana uses M17_ANALYST and inherits the report permissions. Granting the database role to her account role implicitly supplies USAGE on its containing database. The reporting schema still needs its own USAGE. The team can later reuse REPORT_READER in another approved account role without copying each table grant.

Grant a database role to an account role or another database role in the same database. Within this pattern, use grants to account roles to make the database role available to users. A database role cannot be selected with USE ROLE.

Connect one database’s privileges to an active account role The report privileges arrive through the database role. Warehouse access arrives through a separate grant on the account role.
  1. REPORTING schema and ORDERS tableGrant USAGE and SELECT to M17_ACCESS_LAB.REPORT_READER
  2. M17_ACCESS_LAB.REPORT_READERInherit data access to M17_ANALYST account role
  3. M17_LAB_WHGrant warehouse USAGE to M17_ANALYST account role

Connect one database role to a session

Use a disposable account, an approved warehouse called M17_LAB_WH and a test operator who can use SYSADMIN and SECURITYADMIN. Substitute the warehouse and the test operator’s exact SQL user identifier. Use fresh M17D_DB and M17D_READER names. An account role is an active session role that can carry compute and several data bundles. A database role contains a reviewed set of privileges inside one database.

Create a two-row report and its data role

SYSADMIN owns these lab objects. CREATE DATABASE ROLE gives the role USAGE on its parent database implicitly. The explicit USAGE and SELECT below let the role reach the schema and read the table. The role cannot hold warehouse USAGE.

SQL · configuration template
USE ROLE SYSADMIN;
USE WAREHOUSE M17_LAB_WH;
CREATE DATABASE M17D_DB;
CREATE SCHEMA M17D_DB.REPORTING;
CREATE TABLE M17D_DB.REPORTING.ORDERS AS
  SELECT column1 AS order_id, column2 AS amount FROM VALUES (101,40),(102,60);
CREATE DATABASE ROLE M17D_DB.REPORT_READER;
GRANT USAGE ON SCHEMA M17D_DB.REPORTING TO DATABASE ROLE M17D_DB.REPORT_READER;
GRANT SELECT ON TABLE M17D_DB.REPORTING.ORDERS TO DATABASE ROLE M17D_DB.REPORT_READER;
SHOW GRANTS TO DATABASE ROLE M17D_DB.REPORT_READER;

Grant the bundle and test the account role

SECURITYADMIN creates and assigns the account role and grants warehouse usage. SYSADMIN owns REPORT_READER and can grant it. Before the database-role grant, use the warehouse and try the SELECT alone. Expect denial. After the grant, repeat it in the same reader role with secondaries off. Expect ORDER_COUNT 2 and SALES 100.

SHOW GRANTS TO ROLE with INCLUDE HIERARCHY reports which role holds which privilege. A SELECT granted to REPORT_READER stays there. The account role can exercise it by inheritance. Check PUBLIC when a before-test unexpectedly succeeds.

SQL · configuration template
USE ROLE SECURITYADMIN;
CREATE ROLE M17D_READER;
GRANT USAGE ON WAREHOUSE M17_LAB_WH TO ROLE M17D_READER;
GRANT ROLE M17D_READER TO USER <TEST_OPERATOR>;
USE ROLE M17D_READER;
USE SECONDARY ROLES NONE;
USE WAREHOUSE M17_LAB_WH;
-- Run this expected denial separately.
SELECT COUNT(*) AS order_count, SUM(amount) AS sales FROM M17D_DB.REPORTING.ORDERS;

USE ROLE SYSADMIN;
GRANT DATABASE ROLE M17D_DB.REPORT_READER TO ROLE M17D_READER;
USE ROLE SECURITYADMIN;
SHOW GRANTS TO ROLE M17D_READER INCLUDE HIERARCHY;

USE ROLE M17D_READER;
SELECT COUNT(*) AS order_count, SUM(amount) AS sales FROM M17D_DB.REPORTING.ORDERS;

Remove the data role and verify the result

SYSADMIN removes the database-role edge. The account role still has compute but the read should fail again. Run the denial alone. SECURITYADMIN then removes the test membership and account role it created. SYSADMIN removes the disposable database only.

SQL · configuration template
USE ROLE SYSADMIN;
REVOKE DATABASE ROLE M17D_DB.REPORT_READER FROM ROLE M17D_READER;
USE ROLE M17D_READER;
-- Expected denial. Run separately.
SELECT COUNT(*) FROM M17D_DB.REPORTING.ORDERS;

USE ROLE SECURITYADMIN;
REVOKE ROLE M17D_READER FROM USER <TEST_OPERATOR>;
DROP ROLE M17D_READER;
USE ROLE SYSADMIN;
DROP DATABASE M17D_DB;

Reuse data grants without sharing every job privilege

Finance and support can inherit the same approved database role while using different warehouses and separate job grants. Create a second database role when the approved data slice differs. Adding a table to the shared role changes access for every parent, so review the grant graph before merging a change.

If a pipeline crosses databases, place each database’s bundle at its own boundary and grant both to the job account role. Fully qualify database-role names in scripts. A role in database A cannot receive privileges on objects in database B.

Explain the design in an interview

Name the rule, then explain how you would prove it.

Why does USE ROLE REPORT_READER fail?

REPORT_READER is a database role. I activate the account role that inherits it. That account role also carries the warehouse grant.

What changes when a second team needs the same data?

I would reuse the data role if its scope matches the approval. I would grant it to the second team’s account role and test the new parent without changing the first team’s compute or job rights.

Words used in this lesson
Account role
An account-scoped role that can be activated in a session.
Database role
A role whose object privileges are scoped to one database.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 2

Snowflake Account Roles vs. Database Roles: Grants and Inheritance

Reporting schema
Orders table
REPORT_READER

Collect the data privileges

The database role groups access to the specific reporting objects.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Collect the data privileges

    The database role groups access to the specific reporting objects.

    Reporting schema → Orders table → REPORT_READER

  2. Activate the job role

    M17_ANALYST inherits the database role and carries compute access.

    REPORT_READER → M17_ANALYST → Analyst session

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Connect report access to the analyst account role

SQL · excerpt
GRANT DATABASE ROLE M17_ACCESS_LAB.REPORT_READER
  TO ROLE M17_ANALYST;

SHOW GRANTS TO ROLE M17_ANALYST INCLUDE HIERARCHY;

What to expect and why

The lab database role owner makes the role grant. Look for the database-role membership and the object grants held by REPORT_READER in the hierarchy output. Check the analyst account role for its warehouse USAGE.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Which role should hold USAGE on the analyst warehouse?

Try it yourself

Show where you would put read access for a second database and how Ana would receive it.

Compare your reasoning

Define an appropriate database role in the second database and grant it to a reviewed account role Ana can activate.

Official sources and curriculum

Module 17 · See module scope

By Rohit Ray · Independent educational lesson · Explore this visual lab