Views and secure views
A view is a named query that you read like a table. A secure view adds protections for its definition and underlying data exposure; it still needs correct grants and filters.
Understand the idea
Imagine a saved report recipe. Each time someone reads a normal view, Snowflake evaluates its query against the underlying data. If order data changes, the view can reflect that change without a separate refresh operation. It is not a frozen export.
| Concept | What it means |
|---|---|
| View | Stores a query definition rather than a separate copy of its result. |
| Secure view | Restricts definition visibility and some optimizations to protect sensitive data. |
| SELECT grant | Controls who can read the exposed result; SECURE does not grant access. |
A concrete example
Northstar gives analysts a view of large orders. They work with a stable name while the query selects the relevant rows and columns.
Remember: A view defines what to show. Permissions decide who may see it.
Explain it step by step · full theory
Understand the idea
Imagine a saved report recipe. Each time someone reads a normal view, Snowflake evaluates its query against the underlying data. If order data changes, the view can reflect that change without a separate refresh operation. It is not a frozen export.
A secure view is useful when exposing sensitive data through a controlled interface. It does not automatically mask every column or filter every tenant. You must choose the columns and predicates and configure access. Some optimizations are restricted, so security can affect performance.
Follow the example
This example uses the two-row ORDERS table from lesson 1. The view returns only rows with an amount of at least 50. The SECURE keyword changes protection behavior, not this filter condition.
Creating the view requires schema creation privileges and access to the underlying objects. A consumer generally needs access to the view and its containers, rather than direct SELECT on its source table. Administrative roles can have broader visibility; secure does not mean invisible to every role.
For the original two orders, the view returns only order 102 with amount 60.00. It does not copy or delete either source row.
Words used in this lesson
- View
- Stores a query definition rather than a separate copy of its result.
- Secure view
- Restricts definition visibility and some optimizations to protect sensitive data.
- SELECT grant
- Controls who can read the exposed result; SECURE does not grant access.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Views and secure views
Start with the requirement
Northstar gives analysts a view of large orders. They work with a stable name while the query selects the relevant rows and columns.
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
- Start with the requirement
Northstar gives analysts a view of large orders. They work with a stable name while the query selects the relevant rows and columns.
- Choose the objects
Compare the responsibilities: View: Stores a query definition rather than a separate copy of its result.; Secure view: Restricts definition visibility and some optimizations to protect sensitive data.; SELECT grant: Controls who can read the exposed result; SECURE does not grant access.
- Explain the outcome
A view defines what to show. Permissions decide who may see it.
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.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- 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.
- 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. - 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.
Before running this lesson
Examples are for reading first. Optional execution requires an authorized learning account, a selected warehouse for queries, and privileges on the named objects. Nothing runs on this website.
Create a standard view
CREATE VIEW L2_OBJECTS_LAB.SALES.ORDER_AMOUNTS AS
SELECT ORDER_ID, AMOUNT FROM L2_OBJECTS_LAB.SALES.ORDERS;
SELECT * FROM L2_OBJECTS_LAB.SALES.ORDER_AMOUNTS ORDER BY ORDER_ID;What to expect and why
With the original setup this returns orders 101 and 102 with amounts 40 and 60. The view saves a query definition, not a separate stored copy of these results. The secure-view example below adds protection behavior and a filter.
Read the example
CREATE SECURE VIEW L2_OBJECTS_LAB.SALES.LARGE_ORDERS AS
SELECT ORDER_ID, AMOUNT FROM L2_OBJECTS_LAB.SALES.ORDERS WHERE AMOUNT >= 50;
SELECT * FROM L2_OBJECTS_LAB.SALES.LARGE_ORDERS;What to expect and why
For the original two orders, the view returns only order 102 with amount 60.00. It does not copy or delete either source row.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
How would you expose order IDs but keep amounts out of a reporting interface?
Compare your reasoning
Select only ORDER_ID in the view definition, grant access to the intended consumer role, and ensure that role cannot bypass the interface through direct table access. SECURE alone does not remove AMOUNT.