Bird
Raised Fist0
Snowflakecloud~10 mins

Creating custom roles in Snowflake - Visual Walkthrough

Choose your learning style10 modes available
Process Flow - Creating custom roles
Start
↓
Define Role Name
↓
Execute CREATE ROLE SQL
↓
Role Created in System
↓
Grant Privileges to Role
↓
Assign Role to Users
↓
Users Can Use Role Permissions
↓
End
The flow shows creating a custom role, granting privileges, and assigning it to users so they can use the permissions.
Execution Sample
Snowflake
CREATE ROLE analyst;
GRANT SELECT ON DATABASE sales_db TO ROLE analyst;
GRANT ROLE analyst TO USER alice;
This code creates a role named 'analyst', grants it select access on a database, and assigns the role to user 'alice'.
Process Table
StepActionSQL ExecutedSystem State ChangeResult
1Create roleCREATE ROLE analyst;Role 'analyst' added to roles listRole 'analyst' exists with no privileges
2Grant privilegeGRANT SELECT ON DATABASE sales_db TO ROLE analyst;Role 'analyst' granted SELECT on sales_dbRole 'analyst' can SELECT from sales_db
3Assign role to userGRANT ROLE analyst TO USER alice;User 'alice' assigned role 'analyst'User 'alice' can use 'analyst' permissions
4EndNo further changesSetup complete
💡 All steps executed successfully; custom role created and assigned.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
roles_list[]['analyst']['analyst']['analyst']['analyst']
analyst_privileges{}{}{'SELECT on sales_db'}{'SELECT on sales_db'}{'SELECT on sales_db'}
alice_roles[][][]['analyst']['analyst']
Key Moments - 2 Insights
Why does the role have no privileges immediately after creation?
Because creating a role only defines it; privileges must be granted separately as shown in step 2 of the execution_table.
Can a user use a role's privileges before the role is assigned to them?
No, as shown in step 3, the user must be assigned the role to use its permissions.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the system state after step 2?
ARole 'analyst' exists but has no privileges
BUser 'alice' assigned role 'analyst'
CRole 'analyst' granted SELECT on sales_db
DNo roles exist yet
💡 Hint
Check the 'System State Change' column in row 2 of execution_table.
At which step does user 'alice' gain the ability to use the 'analyst' role?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Look at the 'Result' column for when 'alice' is assigned the role.
If we skip granting privileges in step 2, what would be the effect?
AUser 'alice' could still SELECT from sales_db
BRole 'analyst' would have no privileges
CRole 'analyst' would have default privileges
DUser 'alice' would be unable to log in
💡 Hint
Refer to the 'key_moments' about role privileges after creation.
Concept Snapshot
CREATE ROLE role_name;
GRANT privileges TO ROLE role_name;
GRANT ROLE role_name TO USER user_name;

Roles start empty; privileges must be granted.
Users gain permissions only after role assignment.
Full Transcript
Creating custom roles in Snowflake involves three main steps. First, you create the role with CREATE ROLE. This adds the role to the system but it has no permissions yet. Next, you grant privileges like SELECT on databases to the role. Finally, you assign the role to users so they can use those permissions. The execution table shows each step's SQL command and how the system state changes. Variables track roles, privileges, and user assignments. Key moments clarify that roles start empty and users need role assignment to gain permissions. The quiz tests understanding of when privileges are granted and when users gain access.

Practice

(1/5)
1. What is the main purpose of creating a custom role in Snowflake?
easy
A. To create a new user account
B. To store data in a new database
C. To run SQL queries faster
D. To control and manage user access permissions

Solution

  1. Step 1: Understand role purpose

    Custom roles in Snowflake are designed to manage what users can do by controlling permissions.
  2. Step 2: Identify correct function

    Creating a role is not about storing data, creating users, or speeding queries, but about access control.
  3. Final Answer:

    To control and manage user access permissions -> Option D
  4. Quick Check:

    Role purpose = Access control [OK]
Hint: Roles control permissions, not data or users [OK]
Common Mistakes:
  • Confusing roles with users
  • Thinking roles store data
  • Assuming roles speed up queries
2. Which of the following is the correct syntax to create a new role named data_analyst in Snowflake?
easy
A. CREATE ROLE data_analyst;
B. NEW ROLE data_analyst;
C. MAKE ROLE data_analyst;
D. ADD ROLE data_analyst;

Solution

  1. Step 1: Recall Snowflake role creation syntax

    The correct command to create a role is CREATE ROLE role_name;.
  2. Step 2: Match syntax with options

    Only CREATE ROLE data_analyst; uses the correct CREATE ROLE syntax.
  3. Final Answer:

    CREATE ROLE data_analyst; -> Option A
  4. Quick Check:

    CREATE ROLE = correct syntax [OK]
Hint: Use CREATE ROLE to make new roles [OK]
Common Mistakes:
  • Using NEW ROLE instead of CREATE ROLE
  • Using MAKE or ADD which are invalid
  • Missing semicolon at the end
3. Given the commands:
CREATE ROLE analyst;
GRANT USAGE ON DATABASE sales_db TO ROLE analyst;
GRANT ROLE analyst TO USER alice;

What permission does user alice have on sales_db?
medium
A. No permissions on sales_db
B. Only USAGE permission on sales_db
C. ALL permissions on sales_db
D. SELECT permission on sales_db

Solution

  1. Step 1: Analyze role creation and grants

    The role analyst is created and given USAGE permission on sales_db.
  2. Step 2: Check role assignment to user

    User alice is granted the analyst role, so she inherits its permissions.
  3. Final Answer:

    Only USAGE permission on sales_db -> Option B
  4. Quick Check:

    Role grants USAGE, user inherits USAGE [OK]
Hint: User gets permissions of assigned roles [OK]
Common Mistakes:
  • Assuming no permissions without direct grant
  • Confusing USAGE with SELECT permission
  • Ignoring role inheritance
4. You run this command:
CREATE ROLE analyst

but get an error. What is the likely cause?
medium
A. You must create a user before creating a role
B. Role name analyst is reserved and cannot be used
C. Missing semicolon at the end of the command
D. CREATE ROLE command is not supported in Snowflake

Solution

  1. Step 1: Check command syntax

    Snowflake commands require a semicolon at the end to execute properly.
  2. Step 2: Evaluate other options

    Role names like analyst are allowed, users are independent of roles, and CREATE ROLE is supported.
  3. Final Answer:

    Missing semicolon at the end of the command -> Option C
  4. Quick Check:

    Semicolon ends command [OK]
Hint: Always end SQL commands with a semicolon [OK]
Common Mistakes:
  • Forgetting semicolon causes syntax error
  • Thinking role names are restricted
  • Believing users must exist first
5. You want to create a custom role report_viewer that can only read data from the reports schema in the analytics database. Which sequence of commands correctly achieves this?
hard
A. CREATE ROLE report_viewer; GRANT USAGE ON DATABASE analytics TO ROLE report_viewer; GRANT USAGE ON SCHEMA analytics.reports TO ROLE report_viewer; GRANT SELECT ON ALL TABLES IN SCHEMA analytics.reports TO ROLE report_viewer;
B. CREATE ROLE report_viewer; GRANT SELECT ON DATABASE analytics TO ROLE report_viewer;
C. CREATE ROLE report_viewer; GRANT ALL ON SCHEMA analytics.reports TO ROLE report_viewer;
D. CREATE ROLE report_viewer; GRANT USAGE ON DATABASE analytics TO ROLE report_viewer; GRANT SELECT ON SCHEMA analytics.reports TO ROLE report_viewer;

Solution

  1. Step 1: Create the role

    Use CREATE ROLE report_viewer; to make the role.
  2. Step 2: Grant USAGE on database and schema

    Granting USAGE on the database and schema allows access to objects inside.
  3. Step 3: Grant SELECT on all tables in the schema

    Grant SELECT on all tables to allow read access to data.
  4. Step 4: Evaluate options

    CREATE ROLE report_viewer; GRANT USAGE ON DATABASE analytics TO ROLE report_viewer; GRANT USAGE ON SCHEMA analytics.reports TO ROLE report_viewer; GRANT SELECT ON ALL TABLES IN SCHEMA analytics.reports TO ROLE report_viewer; correctly grants USAGE and SELECT at proper levels. CREATE ROLE report_viewer; GRANT SELECT ON DATABASE analytics TO ROLE report_viewer; misses schema and USAGE grants. CREATE ROLE report_viewer; GRANT ALL ON SCHEMA analytics.reports TO ROLE report_viewer; grants ALL which is too broad. CREATE ROLE report_viewer; GRANT USAGE ON DATABASE analytics TO ROLE report_viewer; GRANT SELECT ON SCHEMA analytics.reports TO ROLE report_viewer; grants SELECT on schema which is invalid; SELECT must be on tables.
  5. Final Answer:

    CREATE ROLE report_viewer; GRANT USAGE ON DATABASE analytics TO ROLE report_viewer; GRANT USAGE ON SCHEMA analytics.reports TO ROLE report_viewer; GRANT SELECT ON ALL TABLES IN SCHEMA analytics.reports TO ROLE report_viewer; -> Option A
  6. Quick Check:

    Grant USAGE + SELECT on tables = read access [OK]
Hint: Grant USAGE on DB/schema, SELECT on tables for read-only role [OK]
Common Mistakes:
  • Granting SELECT on schema instead of tables
  • Missing USAGE grants on database or schema
  • Granting ALL permissions instead of SELECT only
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard