Home Database Views, Secure Views, Caching & Alerts: A Practical Guide
Intermediate 5 min · July 17, 2026
Views, Secure Views, Result Caching, and Alerts in Snowflake

Views, Secure Views, Caching & Alerts: A Practical Guide

Master Snowflake views (standard, secure, materialized), result caching, and alerts with production-ready examples.

N
Naren Founder & Principal Engineer

20+ years shipping high-throughput database systems. Written from production experience, not tutorials.

Follow
Production
production tested
July 17, 2026
last updated
2,439
articles · all by Naren
Before you start⏱ 20-25 min read
  • Basic knowledge of SQL (SELECT, JOIN, GROUP BY).
  • Access to a Snowflake account with permissions to create views, materialized views, and alerts.
  • Familiarity with Snowflake's ACCOUNT_USAGE schema (optional but helpful).
 ● Production Incident 🔎 Debug Guide ⚙ Triage Commands
Quick Answer
  • Views are saved SQL queries that simplify complex joins and enforce row/column-level security.
  • Secure views hide the view definition and underlying table structure from users.
  • Result caching stores query results for 24 hours, speeding up repeated queries.
  • Alerts notify you when specified conditions (e.g., high credit usage) are met.
  • Materialized views precompute results for faster queries but require maintenance.
✦ Definition~90s read
What is Views, Secure Views, Result Caching, and Alerts in Snowflake?

Snowflake views are virtual tables defined by SQL queries that simplify data access, enforce security, and can be cached or materialized for performance, while alerts notify you of predefined conditions.

Think of a view as a saved search filter on a giant spreadsheet.
Plain-English First

Think of a view as a saved search filter on a giant spreadsheet. Instead of typing the same complex filter every time, you save it and reuse it. A secure view is like a filter that also hides the original data's column names and formulas. Caching is like keeping a photocopy of the result so you don't have to re-scan the whole spreadsheet. Alerts are like setting up a notification when a certain cell value changes.

⚙ Browser compatibility
Latest versions — ✓ supported
ChromeFirefoxSafariEdge

In Snowflake, data is stored in tables, but you often need to present only a subset of that data to different users or applications. This is where views come in. A view is a virtual table defined by a SQL query. It doesn't store data itself; it just stores the query. When you query a view, Snowflake runs the underlying query and returns the result. Views are essential for security (hiding sensitive columns), simplicity (encapsulating complex joins), and consistency (providing a stable interface).

But standard views have limitations: they expose the view definition to users, and they don't cache results. Snowflake addresses these with secure views (which hide the definition) and result caching (which automatically caches query results for 24 hours). For even better performance, materialized views precompute and store results, updating them as base data changes.

Additionally, Snowflake's alerting framework allows you to monitor your warehouse usage, query performance, and data changes. You can set up alerts to send notifications when, for example, credit consumption exceeds a threshold or a specific query pattern is detected.

In this tutorial, you'll learn how to create and manage views (standard, secure, materialized), leverage result caching, and set up alerts. We'll use a sample sales database with tables: customers, orders, and order_items. By the end, you'll be able to design a secure, performant data access layer and monitor your Snowflake environment effectively.

1. Understanding Views in Snowflake

Views are virtual tables defined by a SELECT statement. They don't store data; they store the query. When you query a view, Snowflake executes the underlying query and returns the result. Views are useful for: - Security: Hide sensitive columns (e.g., salary) from certain users. - Simplicity: Encapsulate complex joins and aggregations. - Consistency: Provide a stable interface even if underlying tables change.

In Snowflake, you can create a view using CREATE VIEW. Here's an example with our sales database:

CREATE VIEW customer_orders AS SELECT c.customer_id, c.name, o.order_id, o.order_date, o.total_amount FROM customers c JOIN orders o ON c.customer_id = o.customer_id;

This view joins customers and orders, making it easy for analysts to query customer order data without writing the join each time.

Views can be updated if they meet certain conditions (e.g., no aggregations, no DISTINCT). However, most views are read-only. Snowflake also supports recursive views and views with common table expressions (CTEs).

create_view.sqlSQL
1
2
3
4
5
6
7
8
9
10
11
12
13
-- Create a view that shows customer order summary
CREATE VIEW customer_order_summary AS
SELECT
  c.customer_id,
  c.name,
  COUNT(o.order_id) AS order_count,
  SUM(o.total_amount) AS total_spent
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id, c.name;

-- Query the view
SELECT * FROM customer_order_summary WHERE total_spent > 1000;
Output
CUSTOMER_ID | NAME | ORDER_COUNT | TOTAL_SPENT
------------|------------|-------------|------------
101 | Alice | 5 | 2500.00
102 | Bob | 3 | 1500.00
💡View Naming Conventions
📊 Production Insight
In production, avoid nesting views too deeply (e.g., views on views on views) as it can degrade performance. Snowflake's optimizer handles simple views well, but deep nesting may lead to suboptimal execution plans.
🎯 Key Takeaway
Views simplify complex queries and enhance security by exposing only necessary columns.

2. Secure Views: Hiding the Definition

Standard views expose their definition to any user with the MONITOR privilege on the view or schema. This can be a security risk if the view definition reveals table names, column names, or business logic. Secure views solve this by hiding the view definition from users. Only the view owner or users with the OWNERSHIP privilege can see the definition.

CREATE SECURE VIEW employee_salary AS SELECT employee_id, name, department FROM employees WHERE role != 'HR'; -- Hides salary column and HR employees

Once created, users can query the view but cannot see the underlying SQL. They also cannot see the base table structure through the view.

Secure views also support row-level security. For example, you can create a secure view that filters rows based on the current user:

CREATE SECURE VIEW user_orders AS SELECT * FROM orders WHERE customer_id = (SELECT customer_id FROM customers WHERE email = CURRENT_USER());

This ensures each user only sees their own orders.

Note: Secure views have a slight performance overhead because Snowflake must enforce the security checks. However, the overhead is minimal for most use cases.

secure_view.sqlSQL
1
2
3
4
5
6
7
8
9
10
11
12
-- Create a secure view that hides salary and filters by department
CREATE SECURE VIEW v_employee_public AS
SELECT employee_id, name, department
FROM employees
WHERE department != 'HR';

-- Try to view the definition (will fail for non-owners)
SHOW VIEWS LIKE 'v_employee_public';
-- The 'text' column will be NULL for non-owners.

-- Query the view
SELECT * FROM v_employee_public;
Output
EMPLOYEE_ID | NAME | DEPARTMENT
------------|------------|-----------
1 | John | Engineering
2 | Jane | Sales
⚠ Secure View Limitations
📊 Production Insight
In production, combine secure views with role-based access control (RBAC). Grant SELECT on the secure view to specific roles, and avoid granting MONITOR privileges on the schema to end users.
🎯 Key Takeaway
Use secure views whenever the view definition or underlying table structure is sensitive.

3. Materialized Views: Precomputed Results for Performance

Materialized views (MVs) store the result of a query physically, like a table. They are automatically refreshed when base data changes (within a few minutes). MVs are ideal for expensive queries that are run frequently, such as aggregations over large tables.

CREATE MATERIALIZED VIEW mv_daily_sales AS SELECT order_date, SUM(amount) AS daily_total FROM orders GROUP BY order_date;

Once created, querying mv_daily_sales is much faster than running the aggregation on the base table because the result is precomputed.

MVs have some restrictions
  • The SELECT statement must be a single table or a join of tables, but with limited support for outer joins.
  • Aggregations are allowed (SUM, COUNT, MIN, MAX, etc.) but not COUNT(DISTINCT).
  • The view cannot use window functions, HAVING, ORDER BY, or LIMIT.
  • The base table must be a permanent table (not a view or external table).

Snowflake automatically maintains MVs. You can also manually refresh them:

ALTER MATERIALIZED VIEW mv_daily_sales REFRESH;

To check if an MV is up-to-date, query the AUTOMATIC_CLUSTERING or the MV's metadata.

MVs consume storage and incur compute costs for maintenance. Use them judiciously for queries that are both expensive and frequent.

materialized_view.sqlSQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- Create a materialized view for monthly sales by product
CREATE MATERIALIZED VIEW mv_monthly_product_sales AS
SELECT
  DATE_TRUNC('month', o.order_date) AS month,
  oi.product_id,
  SUM(oi.quantity * oi.unit_price) AS total_sales
FROM orders o
JOIN order_items oi ON o.order_id = oi.order_id
GROUP BY month, product_id;

-- Query the materialized view
SELECT * FROM mv_monthly_product_sales WHERE month = '2024-01-01';

-- Check refresh history
SELECT * FROM SNOWFLAKE.ACCOUNT_USAGE.MATERIALIZED_VIEW_REFRESH_HISTORY
WHERE MATERIALIZED_VIEW_NAME = 'MV_MONTHLY_PRODUCT_SALES';
Output
MONTH | PRODUCT_ID | TOTAL_SALES
-----------|------------|------------
2024-01-01 | 201 | 15000.00
2024-01-01 | 202 | 8000.00
🔥MV Storage Costs
📊 Production Insight
In production, use MVs for dashboards and reporting where query latency is critical. Set up alerts to monitor MV refresh failures (e.g., when base table schema changes).
🎯 Key Takeaway
Materialized views dramatically improve query performance for expensive aggregations but come with storage and maintenance costs.

4. Result Caching: Automatic Query Acceleration

Snowflake automatically caches the results of queries for 24 hours. If you run the same query again (with the same SQL text and same context), Snowflake returns the cached result instantly, bypassing computation. This is called result caching.

Result caching works for any query, including those on views. It is transparent and requires no configuration. However, there are conditions: - The query must be exactly the same (including whitespace and comments). - The underlying data must not have changed (Snowflake tracks changes at the micro-partition level). - The session context (e.g., role, warehouse) must be the same. - The query must not use non-deterministic functions like CURRENT_TIMESTAMP or RANDOM.

You can check if a query used cached results by looking at the QUERY_HISTORY view:

SELECT query_id, query_text, executed_as, cached_result FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY WHERE query_text LIKE '%customer_order_summary%';

The CACHED_RESULT column shows 'true' if the result was served from cache.

ALTER SESSION SET USE_CACHED_RESULT = FALSE;

This is useful for testing or when you want to force a fresh computation.

Result caching is especially beneficial for views that are queried frequently by multiple users. It reduces warehouse usage and speeds up response times.

result_caching.sqlSQL
1
2
3
4
5
6
7
8
9
10
11
12
-- Run a query on a view
SELECT * FROM customer_order_summary WHERE total_spent > 1000;

-- Run the same query again (will use cache)
SELECT * FROM customer_order_summary WHERE total_spent > 1000;

-- Check if cache was used
SELECT query_id, query_text, cached_result
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
WHERE query_text LIKE '%customer_order_summary%'
ORDER BY start_time DESC
LIMIT 2;
Output
QUERY_ID | QUERY_TEXT | CACHED_RESULT
---------|-----------------------------------------------------------------------------|--------------
abc123 | SELECT * FROM customer_order_summary WHERE total_spent > 1000 | false
abc124 | SELECT * FROM customer_order_summary WHERE total_spent > 1000 | true
💡Cache Invalidation
📊 Production Insight
In production, be aware that result caching can mask performance issues. When troubleshooting slow queries, temporarily disable caching to see the true execution time.
🎯 Key Takeaway
Result caching automatically speeds up repeated queries without any configuration.

5. Setting Up Alerts in Snowflake

Snowflake's alerting framework allows you to create alerts that trigger when specified conditions are met. Alerts can send notifications via email, webhook, or Snowflake's notification integration. Common use cases include: - Monitoring credit usage (e.g., alert when daily credit consumption exceeds a threshold). - Monitoring query performance (e.g., alert when a query runs longer than 10 minutes). - Monitoring data changes (e.g., alert when a table has not been updated in 24 hours).

To create an alert, you need: 1. A notification integration (e.g., email or webhook). 2. A SQL condition that returns true/false. 3. An action (e.g., call a stored procedure or send a notification).

Here's an example that alerts when the total credits used in the last hour exceed 10:

CREATE OR REPLACE ALERT high_credit_usage WAREHOUSE = my_wh SCHEDULE = '60 MINUTE' IF (EXISTS ( SELECT 1 FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY WHERE start_time > DATEADD('hour', -1, CURRENT_TIMESTAMP()) GROUP BY 1 HAVING SUM(credits_used) > 10 )) THEN CALL SYSTEM$SEND_EMAIL('my_email_int', 'admin@company.com', 'High Credit Usage Alert', 'Credits exceeded 10 in the last hour.');

Alerts are managed via the ALERT command. You can enable, disable, or drop alerts.

SELECT * FROM SNOWFLAKE.ACCOUNT_USAGE.ALERT_HISTORY;

Alerts are powerful for proactive monitoring. They help you catch issues before they impact users.

create_alert.sqlSQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-- Create a notification integration for email
CREATE NOTIFICATION INTEGRATION my_email_int
  TYPE = EMAIL
  ENABLED = TRUE;

-- Create an alert for long-running queries
CREATE OR REPLACE ALERT long_running_queries
  WAREHOUSE = my_wh
  SCHEDULE = '10 MINUTE'
  IF (EXISTS (
    SELECT 1
    FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
    WHERE start_time > DATEADD('minute', -10, CURRENT_TIMESTAMP())
      AND execution_time > 300000000  -- 5 minutes in nanoseconds
  ))
  THEN
    CALL SYSTEM$SEND_EMAIL('my_email_int', 'dba@company.com', 'Long Running Query Alert', 'A query ran longer than 5 minutes.');

-- Enable the alert
ALTER ALERT long_running_queries RESUME;
Output
Alert created and enabled.
🔥Alert Costs
📊 Production Insight
In production, set up alerts for critical thresholds like warehouse credit usage, query failures, and data freshness. Combine alerts with Snowflake's resource monitors for comprehensive governance.
🎯 Key Takeaway
Alerts automate monitoring and notification, helping you respond quickly to issues.

6. Best Practices for Views, Caching, and Alerts

Views: - Use secure views for any view that exposes sensitive data or business logic. - Limit the number of nested views to avoid performance degradation. - Document view definitions and their purpose. - Regularly review view usage and drop unused views.

Materialized Views: - Use MVs only for queries that are both expensive and run frequently. - Monitor MV storage and refresh costs. - Set up alerts for MV refresh failures. - Consider using clustering keys on MVs if they are large and queried with filters.

Result Caching: - Be aware that caching can hide performance issues. Periodically test with caching disabled. - Use the CACHED_RESULT column in QUERY_HISTORY to understand cache hit rates. - If you need fresh data every time, consider using a materialized view or disabling cache for critical queries.

Alerts: - Start with simple alerts and gradually add complexity. - Use a dedicated warehouse for alerts to avoid impacting user workloads. - Test alerts in a non-production environment first. - Set up multiple notification channels (email, Slack webhook) for redundancy.

By following these practices, you can build a robust data access layer and monitoring system in Snowflake.

best_practices.sqlSQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- Example: Create a secure materialized view with clustering
CREATE SECURE MATERIALIZED VIEW mv_secure_sales
CLUSTER BY (order_date)
AS
SELECT order_date, region, SUM(amount) AS total
FROM sales
GROUP BY order_date, region;

-- Monitor MV refresh history
SELECT * FROM SNOWFLAKE.ACCOUNT_USAGE.MATERIALIZED_VIEW_REFRESH_HISTORY;

-- Create an alert for MV refresh failures
CREATE OR REPLACE ALERT mv_refresh_failure
  WAREHOUSE = my_wh
  SCHEDULE = '5 MINUTE'
  IF (EXISTS (
    SELECT 1
    FROM SNOWFLAKE.ACCOUNT_USAGE.MATERIALIZED_VIEW_REFRESH_HISTORY
    WHERE status = 'FAILED'
      AND refresh_time > DATEADD('minute', -5, CURRENT_TIMESTAMP())
  ))
  THEN
    CALL SYSTEM$SEND_EMAIL('my_email_int', 'dba@company.com', 'MV Refresh Failure', 'A materialized view refresh failed.');
💡Documentation
🎯 Key Takeaway
Adopting best practices ensures your views, caching, and alerts are efficient, secure, and maintainable.
● Production incidentPOST-MORTEMseverity: high

The Exposed View Definition: A Security Breach

Symptom
Users with access to the view could run SHOW VIEWS and see the full SQL definition, including the names of underlying tables and columns.
Assumption
The developer assumed that granting access to the view alone would hide the underlying table structure and sensitive column names.
Root cause
Standard views in Snowflake expose their definition to any user with the MONITOR privilege on the view or schema. The developer did not use a secure view.
Fix
Replaced the standard view with a secure view using the WITH SECURE keyword. Also revoked unnecessary privileges and added row-level security using a secure view with a WHERE clause.
Key lesson
  • Always use secure views when the view definition or underlying table structure is sensitive.
  • Regularly audit view definitions and permissions.
  • Combine secure views with row-level security to restrict data access per user.
  • Educate developers on the difference between standard and secure views.
  • Use Snowflake's access history to monitor who is querying views.
Production debug guideSymptom to Action4 entries
Symptom · 01
Query on a view is slow, but the same query on the base table is fast.
Fix
Check if the view uses complex joins or functions. Consider creating a materialized view or using a clustered table. Also check if result caching is disabled.
Symptom · 02
Users can see the view definition even though you want it hidden.
Fix
Alter the view to be secure: ALTER VIEW my_view SET SECURE;. Revoke MONITOR privileges on the schema if not needed.
Symptom · 03
A query returns stale data despite recent changes to base tables.
Fix
Check if the query is using result caching. Use ALTER SESSION SET USE_CACHED_RESULT = FALSE; to bypass cache temporarily. For materialized views, check if they are stale and refresh them.
Symptom · 04
Alert is not firing even though conditions are met.
Fix
Verify the alert's condition logic and schedule. Check if the alert is enabled. Look at the alert history in ACCOUNT_USAGE.ALERT_HISTORY.
★ Quick Debug Cheat SheetCommon issues with views, caching, and alerts in Snowflake.
View definition visible to users
Immediate action
Alter view to secure
Commands
ALTER VIEW my_view SET SECURE;
GRANT SELECT ON VIEW my_view TO ROLE analyst;
Fix now
Use secure views for sensitive data.
Query result is stale+
Immediate action
Bypass cache
Commands
ALTER SESSION SET USE_CACHED_RESULT = FALSE;
SELECT * FROM my_view;
Fix now
Re-run query without cache.
Materialized view not updating+
Immediate action
Refresh manually
Commands
ALTER MATERIALIZED VIEW my_mv REFRESH;
SELECT * FROM my_mv;
Fix now
Set up automatic refresh or check base table changes.
Alert not firing+
Immediate action
Check alert history
Commands
SELECT * FROM SNOWFLAKE.ACCOUNT_USAGE.ALERT_HISTORY WHERE ALERT_NAME = 'my_alert';
CALL SYSTEM$RESEND_ALERT('my_alert');
Fix now
Verify condition and schedule.
FeatureStandard ViewSecure ViewMaterialized View
Stores dataNoNoYes
Hides definitionNoYesYes
PerformanceSlow (runs query each time)Slow (runs query each time)Fast (precomputed)
Storage costNoneNoneYes
Maintenance costNoneNoneYes (refresh credits)
Supports DMLIf updatableIf updatableNo (read-only)
Use caseSimple encapsulationSensitive data hidingFrequent expensive queries
⚙ Quick Reference
6 commands from this guide
FileCommand / CodePurpose
create_view.sqlCREATE VIEW customer_order_summary AS1. Understanding Views in Snowflake
secure_view.sqlCREATE SECURE VIEW v_employee_public AS2. Secure Views
materialized_view.sqlCREATE MATERIALIZED VIEW mv_monthly_product_sales AS3. Materialized Views
result_caching.sqlSELECT * FROM customer_order_summary WHERE total_spent > 1000;4. Result Caching
create_alert.sqlCREATE NOTIFICATION INTEGRATION my_email_int5. Setting Up Alerts in Snowflake
best_practices.sqlCREATE SECURE MATERIALIZED VIEW mv_secure_sales6. Best Practices for Views, Caching, and Alerts

Key takeaways

1
Views simplify data access and enhance security; use secure views to hide definitions.
2
Materialized views precompute results for faster queries but require storage and maintenance.
3
Result caching automatically speeds up repeated queries; be aware of its invalidation rules.
4
Alerts enable proactive monitoring of credit usage, query performance, and data changes.
5
Follow best practices like using secure views for sensitive data, monitoring MV costs, and testing alerts.

Common mistakes to avoid

5 patterns
×

Using a standard view to hide sensitive columns without realizing the view definition is visible.

×

Creating a materialized view with a query that includes COUNT(DISTINCT) or window functions.

×

Assuming result caching will always return fresh data after a DML operation.

×

Setting up an alert without a proper warehouse, causing the alert to fail or consume excessive credits.

×

Nesting views too deeply (e.g., view on view on view) without considering performance impact.

INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01JUNIOR
What is a view in Snowflake and how does it differ from a table?
Q02SENIOR
Explain the difference between a secure view and a standard view. When w...
Q03SENIOR
How does Snowflake's result caching work and what are its limitations?
Q04SENIOR
Describe a scenario where you would use a materialized view instead of a...
Q05SENIOR
How can you set up an alert to notify you when a specific table has not ...
Q01 of 05JUNIOR

What is a view in Snowflake and how does it differ from a table?

ANSWER
A view is a virtual table defined by a SQL query. It does not store data; it stores the query. When queried, Snowflake executes the underlying query and returns the result. A table stores data physically. Views are used for security, simplicity, and consistency.
FAQ · 5 QUESTIONS

Frequently Asked Questions

01
Can I update data through a view in Snowflake?
02
What is the difference between a secure view and a standard view?
03
How long does result caching last in Snowflake?
04
Can I create an alert that sends a Slack message?
05
Do materialized views consume credits for maintenance?
N
Naren Founder & Principal Engineer

20+ years shipping high-throughput database systems. Written from production experience, not tutorials.

Follow
Verified
production tested
July 17, 2026
last updated
2,439
articles · all by Naren
🔥

That's Snowflake. Mark it forged?

5 min read · try the examples if you haven't

Previous
Unstructured Data in Snowflake: Directory Tables, File Processing, and REST API
33 / 33 · Snowflake