0
0
SQLquery~10 mins

Why views are needed in SQL - Visual Breakdown

Choose your learning style9 modes available
Concept Flow - Why views are needed
User queries view
View definition runs
Underlying tables accessed
Data returned to user
User sees simplified, secure data
A view acts like a saved query. When you ask the view, it runs the query on the real tables and shows you the result. This helps simplify and secure data access.
Execution Sample
SQL
CREATE VIEW SimpleEmployees AS
SELECT id, name FROM Employees WHERE active = 1;

SELECT * FROM SimpleEmployees;
This creates a view showing only active employees with id and name, then selects all from that view.
Execution Table
StepActionQuery/OperationResult
1Create viewCREATE VIEW SimpleEmployees AS SELECT id, name FROM Employees WHERE active = 1;View SimpleEmployees created
2Query viewSELECT * FROM SimpleEmployees;Runs underlying SELECT on Employees table
3Access tableSELECT id, name FROM Employees WHERE active = 1;Filters active employees
4Return dataResult set with id and name of active employeesData sent to user
5DisplayUser sees simplified employee listQuery ends
💡 Query ends after returning filtered, simplified data from underlying table via view
Variable Tracker
VariableStartAfter Step 2After Step 3Final
View SimpleEmployeesNot createdCreated with definitionDefinition used to query EmployeesUsed to return filtered data
Query ResultEmptyEmptyFiltered active employeesFinal result set returned
Key Moments - 3 Insights
Why does querying a view run a query on the underlying tables?
Because a view is a saved query, when you select from it, the database runs the original query on the real tables to get fresh data (see execution_table step 3).
Can a view hide columns or rows from the user?
Yes, views can show only certain columns or filter rows, so users see only what the view allows (see execution_table step 3 filtering active employees).
Does creating a view store data separately?
No, views do not store data themselves; they just store the query. Data is fetched fresh from tables each time (see variable_tracker for view definition vs data).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what happens at step 3?
AThe view is created and stored
BData is returned to the user
CThe underlying table is queried with filters
DThe query ends
💡 Hint
Check the 'Action' and 'Query/Operation' columns at step 3 in execution_table
According to variable_tracker, what is the state of 'Query Result' after step 3?
AContains filtered active employees
BContains all employees
CEmpty
DContains view definition
💡 Hint
Look at the 'Query Result' row and 'After Step 3' column in variable_tracker
If the view included all employees without filtering, how would the execution_table change at step 3?
AThe query would filter active employees
BThe query would return all employees without filtering
CThe view would not be created
DData would not be returned
💡 Hint
Step 3 shows the filtering condition; removing it means no filtering
Concept Snapshot
Views are saved queries that show data from tables.
They simplify complex queries and hide details.
Views do not store data, only the query.
Querying a view runs its query on tables.
Useful for security and easier data access.
Full Transcript
Views in SQL are like saved queries. When you create a view, you define a query that selects data from one or more tables. When you query the view, the database runs the saved query on the real tables and returns the result. This means views do not store data themselves but show data dynamically. Views help by simplifying complex queries, hiding sensitive columns or rows, and providing a consistent interface to data. For example, a view can show only active employees with selected columns. When you select from this view, the database runs the underlying query filtering active employees and returns that data. This process is shown step-by-step in the execution table and variable tracker. Understanding that views run queries on tables each time helps avoid confusion about data storage and freshness.