Views in Snowflake: Complete Guide with Easy Definitions
What are Views in Snowflake?
A View in Snowflake is a virtual table created using a SQL query that does not store data
physically but retrieves data dynamically from underlying tables when queried.
Views help simplify complex queries, improve security, and provide abstraction over raw data.
Simple Definition:
A view in Snowflake is a saved SQL query that behaves like a table but does not store
data.
Why Views are Important
Views help to: 1. Simplify complex SQL logic 2. Improve data security 3. Provide logical abstraction 4.
Reuse SQL code 5. Control data access
How Views Work (Step by Step)
1. A view is created using a SELECT query
2. No data is stored in the view
3. When queried, Snowflake executes the underlying SQL
4. Results are returned to the user
Types of Views in Snowflake
1. Standard (Non-Materialized) Views
Definition: A standard view stores only the SQL logic, not the data.
Use When: - Data changes frequently - Storage cost must be minimized
2. Secure Views
Definition: A secure view hides the underlying table structure and SQL logic from users.
Use When: - Sharing data securely - Protecting sensitive business logic
1
3. Materialized Views
Definition: A materialized view stores precomputed query results to improve performance.
Use When: - Queries are expensive - Data does not change very frequently
Creating a View (Examples)
Standard View
CREATE OR REPLACE VIEW sales_view AS
SELECT order_id, amount
FROM sales;
Secure View
CREATE OR REPLACE SECURE VIEW secure_sales_view AS
SELECT order_id, amount
FROM sales;
Materialized View
CREATE OR REPLACE MATERIALIZED VIEW sales_mv AS
SELECT customer_id, SUM(amount) total_sales
FROM sales
GROUP BY customer_id;
Views vs Tables
Feature View Table
Stores Data No Yes
Storage Cost No Yes
Performance Depends on query Faster
Use Case Abstraction Storage
2
Views vs Materialized Views
Feature View Materialized View
Data Storage No Yes
Refresh Real-time Automatic
Cost Low Higher
Security with Views
Views support: - Column-level security - Row-level filtering - Masking policies
Access Control on Views
Privileges include: - SELECT - REFERENCES
GRANT SELECT ON VIEW sales_view TO ROLE analyst_role;
Performance Considerations
• Views re-run SQL every time
• Complex views may be slow
• Materialized views improve performance but use storage
Best Practices for Views
1. Use views for abstraction
2. Use secure views for sensitive data
3. Avoid overly complex nested views
4. Use materialized views selectively
5. Document views clearly
Common Mistakes
• Using views for heavy aggregations
• Not using secure views when required
• Overusing materialized views
3
Views in Real-Time Projects
Common usage: - Business-friendly reporting layers - Security-controlled access for analysts - Shared
datasets across teams
Summary
• Views are virtual tables
• Simplify queries and improve security
• Types: Standard, Secure, Materialized
• Choose based on performance and cost
One-Line Definition:
A view in Snowflake is a virtual table that provides reusable, secure, and simplified access
to data without storing it physically.