How to CREATE VIEW in Snowflake

Galaxy Glossary

How do I create a view in Snowflake?

CREATE VIEW defines a named, reusable virtual table based on a SELECT query in Snowflake.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

How to CREATE VIEW in Snowflake

CREATE VIEW lets you store complex SELECT logic as a reusable, secure object.

Why use CREATE VIEW in Snowflake?

Encapsulate business logic, simplify queries, and control column exposure without replicating data. Views update automatically when underlying data changes, saving maintenance time.

What is the full CREATE VIEW syntax?

Snowflake supports OR REPLACE, SECURE, RECURSIVE, COPY GRANTS, and more.See the detailed syntax section below.

How do I create a simple view?

Use CREATE VIEW view_name AS SELECT ... to expose frequently used joins or filters. Example shown in the next section.

Can I replace an existing view?

Yes—use CREATE OR REPLACE VIEW. It swaps the definition atomically while keeping the name constant. Combine with COPY GRANTS to retain privileges.

When should I use SECURE views?

Choose SECURE to prevent exposing underlying table data to unauthorized roles.Secure views are required for data that leaves your Snowflake account (e.g., data shares).

Example: aggregating customer spend

The sample query in the example section builds a view showing lifetime spend per customer, ready for dashboards or analysts.

Best practices for CREATE VIEW

1) Name views with business-friendly prefixes (vw_ or v_). 2) Keep SELECT statements deterministic. 3) Avoid ORDER BY unless paired with LIMIT.4) Document columns with comments.

Common mistakes to avoid

See the dedicated mistake section below for quick fixes.

Frequently asked questions

Scroll to the FAQ section for answers on performance, limits, and altering view definitions.

.

Why How to CREATE VIEW in Snowflake is important

How to CREATE VIEW in Snowflake Example Usage


-- Replace existing view & keep grants
CREATE OR REPLACE VIEW vw_top_products
COPY GRANTS
AS
SELECT p.id, p.name, SUM(oi.quantity) AS total_sold
FROM OrderItems oi
JOIN Products p ON p.id = oi.product_id
GROUP BY p.id, p.name
HAVING SUM(oi.quantity) > 100
ORDER BY total_sold DESC;

How to CREATE VIEW in Snowflake Syntax


CREATE [ OR REPLACE ] [ SECURE | RECURSIVE ] VIEW [ IF NOT EXISTS ] <view_name>
    [ ( <column_name> [ COMMENT <string> ] [ , ... ] ) ]
    [ COPY GRANTS ]
    [ COMMENT = <string> ]
    [ ROW ACCESS POLICY <policy_name> ON ( <column_name> [, ...] ) ]
AS
SELECT ... ;

-- Ecommerce-focused examples
-- 1. Customer lifetime spend
CREATE VIEW vw_customer_spend AS
SELECT c.id, c.name, SUM(o.total_amount) AS lifetime_spend
FROM Customers c
JOIN Orders o ON o.customer_id = c.id
GROUP BY c.id, c.name;

-- 2. Secure view hiding emails
CREATE SECURE VIEW vw_customer_public AS
SELECT id, name
FROM Customers;

Common Mistakes

Frequently Asked Questions (FAQs)

Does a view store data?

No. A view is virtual; it runs the underlying SELECT at query time.

Are views slower than tables?

Performance matches the optimised SELECT plan. Materialise complex logic into a table if latency becomes critical.

Can I alter a view without recreation?

Use CREATE OR REPLACE VIEW. ALTER VIEW only renames or adds comments; it cannot change the SELECT.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.