BigQuery · DDL statement
BigQuery CREATE VIEW
CREATE VIEW saves a query under a table-like name. A BigQuery view stores no data and re-runs its query on every use, billed for the underlying tables' bytes. Authorize the view on the source dataset to share a filtered subset without granting access to the tables.
CREATE VIEW name AS query stores only the SQL. Every query that reads the view runs that SQL again against the current data, and on-demand you pay for the bytes of all columns the combined query reads from the underlying tables. Filters you apply to the view are pushed into it, so a view over a partitioned table still prunes partitions when you filter on the partitioning column; a view cannot be partitioned or clustered itself. Use CREATE OR REPLACE VIEW to change the definition and IF NOT EXISTS to create it once. An optional column list renames the output columns and can carry descriptions: CREATE VIEW v (id OPTIONS (description = '...'), total) AS ....
The view body is resolved against the project that owns the view, so a table without a project prefix always means the view's own project, whoever queries it. If you create the view in another project than the one running the statement, every reference must be fully qualified. Views cannot reference query parameters, temporary tables or temporary UDFs, and the schema is captured at creation: if the base table changes, the reported schema goes stale until you recreate the view, although queries still return correct results. Views are read-only, can be nested up to 16 levels (queries work through 15), and the defining SQL can be up to 256 K characters.
An authorized view lets people query the view without having access to the source tables. Put the view in a different dataset from the data, grant users roles/bigquery.dataViewer on the view's dataset (and the BigQuery Job User role to run queries), then add the view to the source dataset's authorized views (console Sharing > Authorize views, the API, bq or Terraform; there is no SQL statement for this step). Both datasets must be in the same location. Combined with a filter on SESSION_USER(), an authorized view returns each user only their own rows. A dataset's access list can hold up to 2,500 authorized resources; authorized datasets avoid authorizing views one by one.
Syntax
CREATE [OR REPLACE] VIEW [IF NOT EXISTS] view_name
[(column_name [OPTIONS (description = '...')][, ...])]
[OPTIONS (expiration_timestamp = ..., description = '...', labels = [...], friendly_name = '...')]
AS query_expression
ALTER VIEW view_name SET OPTIONS (...)
DROP VIEW [IF EXISTS] view_nameArguments and return value
| Argument | Description |
|---|---|
view_name | project.dataset.view. Views share the namespace of tables in the dataset. |
column list | Optional new names for the output columns, matched by position, with optional descriptions. Must have as many names as the query has columns. |
OPTIONS | expiration_timestamp, description, friendly_name, labels, privacy_policy and tags. |
query_expression | Any GoogleSQL query, including WITH RECURSIVE. No query parameters, temp tables or temp functions. |
Returns: A logical view. Querying it runs the stored query against the current data of the underlying tables.
Examples
A reporting view with column descriptions
CREATE OR REPLACE VIEW `project.reporting.paid_orders`
(
order_id OPTIONS (description = 'Order ID from the shop backend'),
customer_id,
order_date,
amount OPTIONS (description = 'Gross amount in EUR')
)
OPTIONS (description = 'Paid orders only; refunds excluded')
AS
SELECT order_id, customer_id, DATE(created_at), amount
FROM `project.dataset.orders`
WHERE status = 'paid';Filtering a view still prunes partitions
If orders is partitioned by DATE(created_at), the filter on order_date is pushed into the view and only one week of partitions is read and billed.
SELECT customer_id, SUM(amount) AS revenue
FROM `project.reporting.paid_orders`
WHERE order_date BETWEEN '2026-11-16' AND '2026-11-22'
GROUP BY customer_id;Row-level filtering in an authorized view
Each account manager sees only their own accounts. After creating it in the shared dataset, add the view as an authorized view on the dataset that holds accounts, and grant managers read access to shared only.
CREATE OR REPLACE VIEW `project.shared.my_accounts` AS
SELECT account_id, account_name, mrr, renewal_date
FROM `project.crm.accounts`
WHERE owner_email = SESSION_USER();Common mistakes
- Expecting a view to cache its result. Every query re-runs the view's SQL and is billed for the underlying bytes; for expensive aggregations queried often, use a materialized view or a scheduled table.
- Stacking views without looking at the cost. A view built on three other views is one big query: its bytes are the sum of every table touched. Check the dry-run estimate of a query on the top view.
- Creating an authorized view in the same dataset as its source data. Users with access to that dataset also see the tables; put views in a separate dataset and authorize them on the source.
- Using
SELECT *in a view over a table whose schema changes. The view's stored schema does not update; recreate the view after adding columns, or list the columns explicitly. - Referencing a temporary table or temporary function in the view body. Views can only use permanent objects, and references must include at least the dataset.
Cost and performance
- A view adds no cost of its own, but each query on it bills the underlying columns read. Keep
SELECT *out of views that sit on wide tables, and expose the partitioning column so callers can filter on it. - Results of a query on a view can come from the query cache like any query, as long as the underlying tables have not changed and the query is deterministic.
FAQ
What is the difference between a view and a materialized view in BigQuery?
A view stores SQL and re-runs it on every query. A materialized view stores precomputed results, refreshes them automatically and supports a narrower set of SQL.
How do I create an authorized view in BigQuery?
Create the view in a separate dataset, grant users read access to that dataset and job creation rights in their project, then add the view under Authorize views on the source dataset. The authorization step is done in the console, API, bq or Terraform, not in SQL.
Do I pay for querying a view?
Yes, on-demand you are billed for the bytes the view's query reads from its underlying tables, every time. Creating or dropping a view processes no bytes.
Related
Errors you may hit
More DDL statements
All BigQuery DDL statements · All statements and clauses · BigQuery error messages
