How to CREATE VIEW in BigQuery

Galaxy Glossary

How do I create a view in BigQuery?

CREATE VIEW builds a saved, queryable virtual table based on a SELECT statement without storing data.

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

What does CREATE VIEW do in BigQuery?

CREATE VIEW stores a SQL query as a reusable object.When you query the view, BigQuery runs the underlying SELECT on demand, so no data is duplicated.

When should I use a view?

Use views to encapsulate business logic, simplify joins across Customers, Orders, and OrderItems, or expose only specific columns to analysts.

How do I create a basic view?

Run CREATE VIEW `project.analytics.customer_orders` AS ... with a SELECT statement that joins your ecommerce tables.

Can I overwrite an existing view?

Yes—add OR REPLACE to refresh a view without dropping grants.

How do I secure a view?

Grant dataset-level access or use authorized views to limit exposure to raw tables.

Best practices

Keep view logic small, reference fully-qualified table names, add comments in the view SQL and use dataset naming like analytics or reporting.

Example: daily revenue view

The example below shows a production-grade view for aggregating daily revenue per customer.

.

Why How to CREATE VIEW in BigQuery is important

How to CREATE VIEW in BigQuery Example Usage


-- Create or replace a view that shows total spend per customer
CREATE OR REPLACE VIEW `shop.analytics.customer_lifetime_value` AS
SELECT
  c.id   AS customer_id,
  c.name AS customer_name,
  SUM(o.total_amount) AS lifetime_value,
  COUNT(o.id)         AS order_count,
  MIN(o.order_date)   AS first_purchase,
  MAX(o.order_date)   AS last_purchase
FROM `shop.raw.Customers` AS c
JOIN `shop.raw.Orders`    AS o ON o.customer_id = c.id
GROUP BY customer_id, customer_name;

How to CREATE VIEW in BigQuery Syntax


CREATE [OR REPLACE] [TEMP | TEMPORARY] VIEW [IF NOT EXISTS] `project.dataset.view_name`
[(column_list)]
[OPTIONS (expiration_timestamp=TIMESTAMP 'YYYY-MM-DD HH:MI:SS', description="text")]
AS
SELECT
  c.id   AS customer_id,
  c.name AS customer_name,
  DATE(o.order_date) AS order_day,
  SUM(oi.quantity * p.price) AS daily_revenue
FROM `project.raw.Customers` AS c
JOIN `project.raw.Orders`      AS o  ON o.customer_id = c.id
JOIN `project.raw.OrderItems`  AS oi ON oi.order_id   = o.id
JOIN `project.raw.Products`    AS p  ON p.id          = oi.product_id
GROUP BY customer_id, customer_name, order_day;

Common Mistakes

Frequently Asked Questions (FAQs)

Does a view cost storage?

No. A view stores only metadata. You pay for bytes processed when querying the view.

Can I reference views inside other views?

Yes. Nesting is supported, but keep dependency chains short for easier maintenance.

How do I change a view's definition?

Use CREATE OR REPLACE VIEW. Permissions remain intact, and you avoid dropping dependent objects.

Want to learn about other SQL terms?

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