What if a simple command could stop security mistakes and save hours of work?
Why Granting and revoking privileges in Snowflake? - Purpose & Use Cases
Imagine you have a big office building where many people need access to different rooms. You write down who can enter which room on paper and hand it out. When someone leaves or changes roles, you have to find all those papers and update them manually.
This manual way is slow and confusing. You might forget to update some papers, giving someone access they shouldn't have or blocking someone who needs it. It's easy to make mistakes that cause security problems or slow down work.
Granting and revoking privileges in Snowflake lets you control who can do what with just a few commands. You can quickly give or take away access, and Snowflake keeps track of it safely and clearly. This stops mistakes and saves time.
Manually telling each person their access and writing it down.GRANT SELECT ON TABLE sales TO ROLE analyst; REVOKE INSERT ON TABLE sales FROM ROLE intern;
You can easily manage who can see or change data, keeping your system safe and organized without hassle.
A company hires a new analyst who needs to see sales data but not change it. With a simple command, you grant them read access. Later, when they leave, you revoke it instantly to protect the data.
Manual access control is slow and error-prone.
Granting and revoking privileges automates and secures access management.
This keeps data safe and saves time for everyone.
Practice
Solution
Step 1: Understand the role of privileges
Privileges control what actions roles can perform on database objects like tables or views.Step 2: Identify the purpose of granting privileges
Granting privileges gives roles permission to do specific tasks, such as SELECT or INSERT on tables.Final Answer:
To allow roles to perform specific actions on database objects -> Option AQuick Check:
Grant privileges = Allow role actions [OK]
- Confusing privileges with user creation
- Thinking privileges delete roles
- Assuming privileges backup data
sales_data to a role named analyst_role?Solution
Step 1: Recall the correct GRANT syntax
The syntax is: GRANT <privilege> ON <object_type> <object_name> TO ROLE <role_name>;Step 2: Match the syntax to the options
GRANT SELECT ON TABLE sales_data TO ROLE analyst_role; matches the correct order and keywords exactly.Final Answer:
GRANT SELECT ON TABLE sales_data TO ROLE analyst_role; -> Option DQuick Check:
GRANT privilege ON object TO ROLE [OK]
- Mixing order of keywords
- Placing role before privilege
- Using TO TABLE instead of TO ROLE
GRANT SELECT ON TABLE customers TO ROLE sales_role; REVOKE SELECT ON TABLE customers FROM ROLE sales_role; GRANT INSERT ON TABLE customers TO ROLE sales_role;
What privileges does
sales_role have on the customers table after these commands?Solution
Step 1: Analyze the first GRANT
The rolesales_roleis granted SELECT privilege oncustomers.Step 2: Analyze the REVOKE
The SELECT privilege is revoked fromsales_role, removing that permission.Step 3: Analyze the second GRANT
The role is granted INSERT privilege oncustomers.Final Answer:
Only INSERT -> Option BQuick Check:
Revoked SELECT, granted INSERT = INSERT only [OK]
- Assuming revoked privileges remain
- Thinking grants accumulate without revokes
- Confusing privilege types
REVOKE ALL PRIVILEGES ON DATABASE sales_db FROM ROLE marketing_role;
But the privileges are not removed. What is the most likely reason?
Solution
Step 1: Check if the role has privileges
If the role has no privileges on the database, revoking does nothing.Step 2: Verify syntax and object existence
REVOKE ALL PRIVILEGES is valid syntax, and revoking is done on roles, not users. Assume sales_db exists.Final Answer:
The role marketing_role does not have any privileges on sales_db -> Option AQuick Check:
Revoking non-existent privileges has no effect [OK]
- Assuming syntax error with REVOKE ALL PRIVILEGES
- Trying to revoke from users directly
- Ignoring role privilege state
data_scientist to both read and write data in tables of the analytics schema but prevent it from dropping any tables. Which set of commands correctly grants and restricts privileges?Solution
Step 1: Grant read and write privileges
Grant SELECT, INSERT, and UPDATE to allow reading and writing data.Step 2: Revoke DROP privilege
Explicitly revoke DROP to prevent deleting tables.Step 3: Evaluate other options
GRANT ALL PRIVILEGES ON SCHEMA analytics TO ROLE data_scientist; REVOKE DROP ON SCHEMA analytics FROM ROLE data_scientist; grants ALL privileges then revokes DROP, which is valid but less precise. GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA analytics TO ROLE data_scientist; does not revoke DROP, so drop is allowed. GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA analytics TO ROLE data_scientist; GRANT DROP ON SCHEMA analytics TO ROLE data_scientist; grants DROP, which is opposite of requirement.Final Answer:
GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA analytics TO ROLE data_scientist; REVOKE DROP ON SCHEMA analytics FROM ROLE data_scientist; -> Option CQuick Check:
Grant needed privileges, revoke unwanted ones [OK]
- Granting ALL privileges without revoking DROP
- Not revoking DROP privilege
- Granting DROP privilege by mistake
Ready to prove it?
Pass the test and this pattern moves unknown
