Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a VIEW in SQL?
A VIEW is a virtual table based on the result of a SQL query. It does not store data itself but shows data from one or more tables.
Click to reveal answer
beginner
Write the basic syntax to create a VIEW in SQL.
CREATE VIEW view_name AS SELECT column1, column2 FROM table_name WHERE condition;
Click to reveal answer
intermediate
Can you update data through a VIEW?
Sometimes yes, if the VIEW is simple and directly maps to one table without complex joins or aggregations. Otherwise, updates are not allowed.
Click to reveal answer
beginner
What happens if you try to SELECT from a VIEW?
The database runs the underlying query of the VIEW and returns the result as if it was a table.
Click to reveal answer
beginner
How do you remove a VIEW from the database?
Use the command: DROP VIEW view_name;
Click to reveal answer
What does the CREATE VIEW statement do?
AInserts data into a table
BDeletes a table from the database
CUpdates data in a table
DCreates a virtual table based on a SELECT query
✗ Incorrect
CREATE VIEW defines a virtual table using a SELECT query.
Which keyword is used to define the columns shown in a VIEW?
AAS
BSELECT
CWHERE
DFROM
✗ Incorrect
SELECT specifies the columns shown in a VIEW.
Can a VIEW contain data itself?
AYes, but only temporary data
BYes, it stores data permanently
CNo, it only shows data from tables
DOnly if created with INSERT
✗ Incorrect
A VIEW does not store data; it shows data from underlying tables.
How do you delete a VIEW named 'employee_view'?
ADROP VIEW employee_view;
BDELETE VIEW employee_view;
CREMOVE VIEW employee_view;
DERASE VIEW employee_view;
✗ Incorrect
DROP VIEW is the correct command to remove a VIEW.
Which of these is a valid reason to use a VIEW?
ATo simplify complex queries
BTo permanently store data
CTo speed up data insertion
DTo delete tables
✗ Incorrect
Views help simplify complex queries by encapsulating them.
Explain what a VIEW is and how to create one using SQL.
Think of a VIEW as a saved SELECT query that looks like a table.
You got /3 concepts.
Describe how you can use a VIEW and how to remove it when no longer needed.
Views are virtual tables you can query like real tables.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the CREATE VIEW statement in SQL?
easy
A. To save a SELECT query as a virtual table
B. To permanently store data in the database
C. To delete rows from a table
D. To update existing records in a table
Solution
Step 1: Understand what a view is
A view is a virtual table created by saving a SELECT query.
Step 2: Identify the purpose of CREATE VIEW
CREATE VIEW stores the SELECT query so you can use it like a table without storing data.
Final Answer:
To save a SELECT query as a virtual table -> Option A
Quick Check:
CREATE VIEW = virtual table [OK]
Hint: Views save SELECT queries as virtual tables [OK]
Common Mistakes:
Thinking views store data physically
Confusing CREATE VIEW with INSERT or UPDATE
Assuming views delete or modify data
2. Which of the following is the correct syntax to create a view named EmployeeView that selects all columns from the Employees table?
easy
A. CREATE EmployeeView VIEW AS SELECT * FROM Employees;
B. CREATE VIEW EmployeeView AS SELECT * FROM Employees;
C. VIEW CREATE EmployeeView AS SELECT * FROM Employees;
D. CREATE VIEW Employees AS SELECT * FROM EmployeeView;
Solution
Step 1: Recall the correct CREATE VIEW syntax
The syntax is: CREATE VIEW view_name AS SELECT ...
Step 2: Match the syntax with options
CREATE VIEW EmployeeView AS SELECT * FROM Employees; matches the correct syntax exactly.
Final Answer:
CREATE VIEW EmployeeView AS SELECT * FROM Employees; -> Option B
Quick Check:
CREATE VIEW view_name AS SELECT ... [OK]
Hint: CREATE VIEW view_name AS SELECT ... [OK]
Common Mistakes:
Swapping keywords CREATE and VIEW
Mixing table and view names incorrectly
Using wrong keyword order
3. Given the view creation: CREATE VIEW ActiveUsers AS SELECT id, name FROM Users WHERE active = 1; What will the query SELECT * FROM ActiveUsers; return?
medium
A. Only users with active = 1
B. Only user IDs without names
C. An error because views cannot filter data
D. All users including inactive ones
Solution
Step 1: Understand the view definition
The view selects id and name from Users where active = 1, so only active users are included.
Step 2: Analyze the SELECT from the view
Selecting * from ActiveUsers returns all columns defined in the view, filtered by active = 1.
Final Answer:
Only users with active = 1 -> Option A
Quick Check:
View filters rows = active users only [OK]
Hint: View returns filtered rows as defined in SELECT [OK]
Common Mistakes:
Assuming view returns all table rows
Thinking views cannot filter data
Expecting columns not in view to appear
4. Identify the error in this view creation statement: CREATE VIEW SalesView SELECT * FROM Sales;
medium
A. SELECT * is not allowed in views
B. View name cannot be SalesView
C. Missing AS keyword before SELECT
D. CREATE VIEW must include WHERE clause
Solution
Step 1: Check the syntax of CREATE VIEW
The correct syntax requires AS before the SELECT statement.
Step 2: Identify the missing keyword
The statement misses AS, causing a syntax error.
Final Answer:
Missing AS keyword before SELECT -> Option C
Quick Check:
CREATE VIEW ... AS SELECT ... [OK]
Hint: Always include AS before SELECT in CREATE VIEW [OK]
Common Mistakes:
Omitting AS keyword
Misplacing SELECT clause
Assuming WHERE clause is mandatory
5. You want to create a view TopProducts that shows product names and total sales only for products with sales over 1000. Which SQL statement correctly creates this view?
hard
A. CREATE VIEW TopProducts AS SELECT product_name, sales FROM Products WHERE sales > 1000;
B. CREATE VIEW TopProducts AS SELECT product_name, SUM(sales) FROM Products GROUP BY product_name WHERE SUM(sales) > 1000;
C. CREATE VIEW TopProducts AS SELECT product_name, SUM(sales) FROM Products WHERE SUM(sales) > 1000 GROUP BY product_name;
D. CREATE VIEW TopProducts AS SELECT product_name, SUM(sales) FROM Products GROUP BY product_name HAVING SUM(sales) > 1000;
Solution
Step 1: Understand the requirement
We need product names and total sales, only for products with total sales over 1000.
Step 2: Use GROUP BY and HAVING correctly
SUM(sales) requires GROUP BY product_name, and filtering on aggregated values uses HAVING.
Step 3: Check each option
CREATE VIEW TopProducts AS SELECT product_name, SUM(sales) FROM Products GROUP BY product_name HAVING SUM(sales) > 1000; uses GROUP BY and HAVING correctly; others misuse WHERE or clause order.
Final Answer:
CREATE VIEW TopProducts AS SELECT product_name, SUM(sales) FROM Products GROUP BY product_name HAVING SUM(sales) > 1000; -> Option D
Quick Check:
Use HAVING for aggregated filters in views [OK]
Hint: Use HAVING for conditions on aggregates in views [OK]