SQL View Management 2 — Questions and Answers
Question 1: Which clause prevents an INSERT or UPDATE through a view from producing rows that the view itself cannot select?
- WITH CHECK OPTION (Correct answer)
- WITH READ ONLY
- WITH GRANT OPTION
- WITH RECURSIVE
Correct answer: WITH CHECK OPTION
WITH CHECK OPTION enforces that modified rows still satisfy the view's WHERE condition.
Question 2: What does CREATE OR REPLACE VIEW do if the view already exists?
- Redefines the existing view (Correct answer)
- Raises a duplicate error
- Drops all dependent views
- Creates a second copy
Correct answer: Redefines the existing view
CREATE OR REPLACE VIEW redefines the view in place without dropping it first.
Question 3: A view defined as SELECT col FROM t WHERE x > 5 is generally updatable only if it references how many base tables?
- One (Correct answer)
- Two
- Three
- Unlimited
Correct answer: One
Simple updatable views typically map to a single underlying base table.
Question 4: Which statement removes a view named sales_summary?
- DROP VIEW sales_summary (Correct answer)
- DELETE VIEW sales_summary
- REMOVE VIEW sales_summary
- TRUNCATE VIEW sales_summary
Correct answer: DROP VIEW sales_summary
DROP VIEW deletes the view definition from the database.
Question 5: What happens to the data in base tables when a view is dropped?
- It remains unchanged (Correct answer)
- It is deleted
- It is archived
- It becomes read only
Correct answer: It remains unchanged
Dropping a view removes only the stored query, not the underlying data.
Question 6: Which feature lets a view physically store its query results for faster reads?
- Materialized view (Correct answer)
- Inline view
- Temporary view
- System view
Correct answer: Materialized view
A materialized view caches the result set on disk and is refreshed periodically.
Question 7: Why might you create a view that selects only certain columns of a table?
- To restrict column access for security (Correct answer)
- To delete unused columns
- To index the table faster
- To duplicate the data
Correct answer: To restrict column access for security
Column-limited views hide sensitive columns while exposing only needed data.
Which clause prevents an INSERT or UPDATE through a view from producing rows that the view itself cannot select?