Use views in Fabric Warehouse and SQL analytics endpoint

Applies to: ✅ SQL analytics endpoint and Warehouse in Microsoft Fabric

A view is a named T-SQL query that you use like a table in Fabric Warehouse or the SQL analytics endpoint. It stores the query definition, not a separate copy of the results.

You can create, alter, and drop views in both Warehouse and the SQL analytics endpoint. Creating a view in the SQL analytics endpoint doesn't change the underlying Delta tables or make their data writable.

Why use views?

Use views to choose how you present data to the people and applications that query it:

  • Hide joins and aggregations. Query combined data through a simple SELECT.
  • Present data for reporting. Choose column names, calculations, and filters for consumers.
  • Publish selected data. Grant access to a view's rows and columns instead of entire tables.
  • Keep a stable query interface. Adapt the view's query when tables change, while keeping the columns available to callers the same.

A view doesn't automatically improve query performance or precompute results. Follow the performance guidelines.

Supported syntax

Use the following syntax to define and query views, refresh metadata, and manage permissions.

Create or alter a view

For T-SQL syntax, see CREATE VIEW (Transact-SQL) and ALTER VIEW (Transact-SQL).

CREATE [ OR ALTER ] VIEW [ schema_name. ] view_name
    [ ( column_name [ ,...n ] ) ]
    [ WITH SCHEMABINDING ]
AS <select_statement>
[;]

ALTER VIEW [ schema_name. ] view_name
    [ ( column_name [ ,...n ] ) ]
AS <select_statement>
[;]

<select_statement> ::=
    [ WITH <common_table_expression> [ ,...n ] ]
    SELECT <select_criteria>

Square brackets indicate optional syntax, braces indicate alternatives, and n indicates repetition. Use CREATE OR ALTER to create a view or update its definition. ALTER requires an existing view.

ENCRYPTION, VIEW_METADATA, and WITH CHECK OPTION aren't supported.

Drop a view

For T-SQL syntax, see DROP VIEW (Transact-SQL).

DROP VIEW [ IF EXISTS ] [ schema_name. ] view_name
[;]

Query a view

Use a view as a source in a SELECT statement, not with EXECUTE. This abbreviated form shows a simple query. For full syntax, see SELECT (Transact-SQL).

SELECT <select_list>
FROM [ schema_name. ] view_name
    [ WHERE <search_condition> ]
    [ ORDER BY <order_by_expression> [ ASC | DESC ] [ ,...n ] ]
[;]

Refresh view metadata

For T-SQL syntax, see sys.sp_refreshview (Transact-SQL).

{ EXEC | EXECUTE } sys.sp_refreshview [ @viewname = ] N'view_name'
[;]

Pass a schema-qualified view name in the current database.

Grant permissions on a view

Use these forms to grant permissions for reading and managing a view. For T-SQL syntax, see GRANT object permissions (Transact-SQL).

GRANT <view_permission> [ ,...n ]
    ON OBJECT::[ schema_name. ] view_name
    TO principal [ ,...n ]
    [ WITH GRANT OPTION ]
[;]

<view_permission> ::=
    ALTER | CONTROL | REFERENCES | SELECT | TAKE OWNERSHIP | VIEW DEFINITION

Use WITH GRANT OPTION to let the recipient grant the permission to others. Querying a view requires SELECT, not EXECUTE.

Deny permissions on a view

Use the same view_permission list as for GRANT. For T-SQL syntax, see DENY (Transact-SQL).

DENY <view_permission> [ ,...n ]
    ON OBJECT::[ schema_name. ] view_name
    TO principal [ ,...n ]
    [ CASCADE ]
[;]

CASCADE also denies the permission to principals who received it from the target principal. It's required when the target holds the permission with GRANT OPTION.

Revoke permissions on a view

Use the same view_permission list as for GRANT. For T-SQL syntax, see REVOKE (Transact-SQL).

REVOKE <view_permission> [ ,...n ]
    ON OBJECT::[ schema_name. ] view_name
    FROM principal [ ,...n ]
    [ CASCADE ]
[;]

CASCADE also revokes permissions delegated by the recipient.

Create, alter, and drop a view

Use schema-qualified names. When you alter a view, include the complete query and any explicit column list. ALTER and CREATE OR ALTER preserve object-level permissions. If you change the columns that the view exposes, review its column-level grants.

Keep each view definition in its own batch. GO separates batches in SQL tools. If you're using an application driver, submit each batch separately without sending GO.

For example, create or update a view over GENERATE_SERIES (Transact-SQL):

CREATE OR ALTER VIEW dbo.vw_Example
AS
    SELECT s.value AS ExampleId
    FROM GENERATE_SERIES(1, 10, 1) AS s;
GO

The view returns the numbers from 1 through 10, so you don't need a sample table.

Use DROP VIEW IF EXISTS to remove a view without an error if it doesn't exist. Dropping the view deletes its permissions, not the underlying tables or their data. It can also break views, procedures, or reports that depend on it. Schema-bound objects that depend on the view can prevent you from dropping it. Alter or drop those objects first. If you recreate the view, reapply its grants.

DROP VIEW IF EXISTS dbo.vw_ObsoleteExample;

View definition

The definition after AS is a query, not a sequence of procedural statements. Within the supported T-SQL surface area, you can:

  • Select from tables and other views.
  • Join sources, filter rows, calculate columns, and aggregate data.
  • Use nonrecursive CTEs and set operators such as UNION and UNION ALL.

List columns explicitly instead of using SELECT * to keep the interface predictable. Give each output column a unique name. You can assign aliases to expressions or provide the view's column list. That list must match the number and order of columns in the query.

You can't use SELECT INTO, an OPTION clause, references to temporary tables or table variables, or statements such as DECLARE, SET, and EXECUTE in a view definition.

Schema binding

WITH SCHEMABINDING binds the view to the schema of its referenced objects. It prevents SQL changes that would invalidate the view, such as dropping a referenced table or column. It doesn't freeze the underlying data.

Use two-part names such as dbo.Sales, reference only objects in the same database, and list columns explicitly. For example, if dbo.Sales already has SaleId and Amount columns:

CREATE OR ALTER VIEW dbo.vw_Sales
WITH SCHEMABINDING
AS
    SELECT SaleId, Amount
    FROM dbo.Sales;
GO

To retain schema binding, use CREATE OR ALTER VIEW with WITH SCHEMABINDING. Before you make an incompatible schema change, alter or drop the dependent schema-bound view.

For lakehouse schema changes, also account for SQL analytics endpoint metadata sync.

Session settings

Fabric saves the ANSI_NULLS and QUOTED_IDENTIFIER settings with the view definition. Set creation-time settings in a preceding batch, not inside the view's query.

Use single quotes for string literals and brackets or double quotes for identifiers with QUOTED_IDENTIFIER ON. Compare nulls with IS NULL or IS NOT NULL. For T-SQL syntax, see SET QUOTED_IDENTIFIER (Transact-SQL).

Limitations

Feature Support
Parameters in a view definition Not supported. Apply filters in the calling query, or use an inline table-valued function for a parameterized query source.
Recursive queries Not supported. Views can reference other views, but don't use recursive definitions.
Indexed views Not supported.
Materialized views Not supported. A regular T-SQL view stores only its definition.
INSERT, UPDATE, or DELETE targeting a view Not supported. In Warehouse, modify the underlying tables instead. The SQL analytics endpoint doesn't support these changes to persisted data.

For platform limitations, see Tables and the T-SQL surface area. For parameterized query sources, see Inline table-valued functions. Use stored procedures for multi-step operations.

Query views

Query a view with SELECT (Transact-SQL):

SELECT ExampleId
FROM dbo.vw_Example;

Apply filters and sorting in your calling query. In this example, you define the variable in the calling query, not in the view:

DECLARE @MinimumId int = 5;

SELECT ExampleId
FROM dbo.vw_Example
WHERE ExampleId > @MinimumId
ORDER BY ExampleId;

You can use ORDER BY in a view definition only with row-limiting syntax such as TOP. It doesn't guarantee the order of the query results. Put ORDER BY in your outer query even if the view uses TOP. You can also join a view to tables or other views.

Security and permissions

To connect to the warehouse or SQL analytics endpoint, you need at least Read permission on the item, either directly or through a workspace role. See Fabric security and SQL granular permissions.

If you're a workspace Admin, Member, or Contributor, you can create views.

Operation Required SQL permission
Create a view CREATE VIEW in the database and ALTER on the target schema.
Bind a view to referenced objects REFERENCES on those objects, in addition to the creation or alteration permissions.
Alter a view or refresh its metadata ALTER on the view.
Drop a view CONTROL on the view or ALTER on its schema.
Query a view SELECT on the view. Access to referenced objects also depends on ownership chaining.
Read a view definition VIEW DEFINITION on the view.
Deny or revoke a permission CONTROL on the view.

You can also meet these requirements through higher-level permissions. To grant a permission, you need GRANT OPTION or a higher permission that lets you grant it.

For example, grant query and definition access separately. Replace ViewReaders with the name of your Microsoft Entra user or group.

GRANT SELECT ON OBJECT::dbo.vw_Example TO [ViewReaders];
GRANT VIEW DEFINITION ON OBJECT::dbo.vw_Example TO [ViewReaders];

You can't run CREATE USER. Fabric creates the database user automatically when you grant or deny permissions.

Use DENY to block a permission, including grants inherited through roles or groups. It doesn't restrict the view's owner. For example, block queries:

DENY SELECT ON OBJECT::dbo.vw_Example TO [ViewReaders];

Use REVOKE to remove an explicit GRANT or DENY without blocking other grants. For example, remove the preceding denial:

REVOKE SELECT ON OBJECT::dbo.vw_Example FROM [ViewReaders];

Removing the denial doesn't restore the earlier explicit GRANT. Other grants can still allow access. A column-level GRANT can take precedence over an object-level DENY; see GRANT (Transact-SQL).

Ownership chaining can let you query a view without separate permission checks on its base tables when the objects have the same owner. If the ownership chain is broken, you need additional permissions. A filtered view doesn't remove table access you already have.

SQL permissions don't secure other access paths to the same lakehouse data, such as Spark. See SQL analytics endpoint security.

Metadata and view definitions

Query these catalog views and functions in the database that contains the view:

Catalog view or function Information
sys.objects (Transact-SQL) Views have type = 'V' and type_desc = 'VIEW'.
sys.views (Transact-SQL) View object IDs, names, schema IDs, and creation and modification dates.
sys.columns (Transact-SQL) View column names, order, type IDs, lengths, precision, scale, and nullability. Filter by the view's object_id.
sys.sql_modules (Transact-SQL) View source text in definition and schema-binding status in is_schema_bound.
OBJECT_ID (Transact-SQL) Returns a view's object ID from its schema-qualified name. Specify 'V' as the object type.
OBJECT_NAME (Transact-SQL) Returns a view's name, without its schema, from its object ID.
OBJECT_SCHEMA_NAME (Transact-SQL) Returns a view's schema name from its object ID.
SCHEMA_NAME (Transact-SQL) Returns a schema name from a schema ID, such as sys.views.schema_id.
OBJECT_DEFINITION (Transact-SQL) Returns a view's T-SQL definition from its object ID, not its name.
sys.sql_expression_dependencies (Transact-SQL) Recorded dependencies between a view and its referenced objects, including other views.

For example, resolve the view's ID, then retrieve its schema, name, and definition:

DECLARE @ViewId int = OBJECT_ID('dbo.vw_Example', 'V');
SELECT @ViewId AS ViewId,
    OBJECT_SCHEMA_NAME(@ViewId) AS SchemaName,
    OBJECT_NAME(@ViewId) AS ViewName,
    OBJECT_DEFINITION(@ViewId) AS ViewDefinition;

The metadata you can see depends on the objects you own and the permissions you have. Name and definition lookups can return NULL if the view doesn't exist or you don't have metadata permissions. SELECT doesn't let you read the definition. These lookups use the current database. Object IDs aren't globally unique.

In sys.sql_expression_dependencies, filter referencing_id by the view's object ID to find what it uses, or referenced_id to find resolved dependents in the current database. Cross-database or unresolved references can have a NULL referenced_id; inspect referenced_database_name, referenced_schema_name, and referenced_entity_name as well. To read this catalog view, you need database-level VIEW DEFINITION and SELECT on sys.sql_expression_dependencies.

Refresh metadata after schema changes

If your view doesn't use schema binding, changes to referenced objects can make its stored metadata out of date. After you make a compatible schema change, refresh the metadata with sys.sp_refreshview (Transact-SQL):

EXEC sys.sp_refreshview @viewname = N'dbo.vw_Example';

The command refreshes metadata, not data. It doesn't fix an invalid query or restore a dropped column. For those changes, update the view definition.

In the SQL analytics endpoint, ensure the underlying table's SQL metadata is synchronized before refreshing dependent views. Refreshing a view doesn't synchronize lakehouse tables.