SQL Flow Field Guide

Read a view as a named query

Explain how a view exposes a reusable query definition and how an outer query adds its own filter.

What you are trying to do

A reporting team publishes a stable open work projection. The view definition is useful to review, while object creation is restricted to an isolated training database.

Work through it

  1. Treat the CREATE VIEW statement as syntax study only. Do not execute it against a real or shared database.
  2. Trace the view's selected columns and Status filter to its base table.
  3. Inspect the second SELECT as the way a caller can add another predicate to the view result.
  4. The exact evidence for this lab is the parsed view definition and the read path shown by the visualizer. No view is created by this lab.

Check your work

The definition names dbo.vw_OpenWork, projects WorkItemId, OwnerId, and Title, and applies Status = N'Open'. The read statement adds Points >= 5. The visualizer identifies one CREATE VIEW and one SELECT statement. Do not execute the CREATE VIEW statement on a live database.

Practice SQL

Open in SQL Flow
-- SAFE SYNTAX STUDY. Do not execute CREATE VIEW against a live or shared database.
CREATE VIEW dbo.vw_OpenWork
AS
    SELECT WorkItemId, OwnerId, Title, Points
    FROM dbo.WorkItem
    WHERE Status = N'Open';
GO
-- Read-only example. Inspect this statement. Run it only in a disposable database that has the matching view and sample table.
SELECT WorkItemId, OwnerId, Title, Points
FROM dbo.vw_OpenWork
WHERE Points >= 5;

Knowledge check

Commands in this lesson

Next lesson Turn a JSON array into typed rows