0
0
SQLquery~10 mins

View as a saved query mental model in SQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - View as a saved query mental model
Write SELECT query
Create View with query
View stores query as saved object
Use View in SELECT like a table
Database runs saved query and returns results
You write a SELECT query and save it as a view. Later, you query the view like a table, and the database runs the saved query to give results.
Execution Sample
SQL
CREATE VIEW TopStudents AS
SELECT name, score FROM Students WHERE score > 90;

SELECT * FROM TopStudents;
Create a view named TopStudents that saves a query for students scoring above 90, then select all from that view.
Execution Table
StepActionQuery/CommandResult/Effect
1Create viewCREATE VIEW TopStudents AS SELECT name, score FROM Students WHERE score > 90;View 'TopStudents' saved with query
2Query viewSELECT * FROM TopStudents;Database runs saved query and returns rows with score > 90
3Return resultsN/ARows of students with score above 90 displayed
💡 View acts as stored query; querying it runs the saved SELECT and returns results.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
TopStudents (view)Not definedDefined as SELECT name, score FROM Students WHERE score > 90Used to run saved queryReturns filtered student rows
Key Moments - 2 Insights
Is the data stored inside the view itself?
No, the view only stores the query, not the data. When you query the view (see execution_table step 2), the database runs the saved query on the actual data.
Can I use a view like a regular table in SELECT statements?
Yes, as shown in execution_table step 2, you can SELECT from the view just like a table, and it returns the query results.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what happens at step 1?
AThe view is created and saved with a query
BThe view data is displayed
CThe view is deleted
DThe database updates the Students table
💡 Hint
Refer to execution_table row 1 under 'Result/Effect'
At which step does the database run the saved query inside the view?
AStep 1
BStep 2
CStep 3
DNever
💡 Hint
See execution_table step 2 'Database runs saved query...'
If the Students table changes after creating the view, what will the view show when queried?
ANo data at all
BOld data from when view was created
CUpdated data based on current Students table
DAn error
💡 Hint
Views run the saved query on current data, see concept_flow last step
Concept Snapshot
CREATE VIEW view_name AS SELECT ...;
- View stores a SELECT query, not data.
- Query the view like a table: SELECT * FROM view_name;
- View runs saved query on current data each time.
- Useful for reusing complex queries easily.
Full Transcript
A view in SQL is like a saved SELECT query. You create it with CREATE VIEW and a SELECT statement. The view itself does not store data but remembers the query. When you SELECT from the view, the database runs the saved query on the current data and returns the results. This lets you reuse complex queries easily by just querying the view as if it were a table.