FlashKeepers

SQL · SQL · College and University

SQL Views and Materialized Views

Creating and using views and materialized views for query reuse and performance, each explained with a short example.

About this set

30 basic cards for SQL SQL. It opens with "What is a view in SQL?" and "What is a materialized view?". More College and University decks are listed below.

30 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is a view in SQL?
Show answerA stored query that acts like a table; contains only the SQL definition, not physical data.
What is a materialized view?
Show answerA view whose results are physically stored and refreshed periodically, unlike regular views.
Basic syntax to create a view?
Show answerCREATE VIEW view_name AS SELECT col1, col2 FROM table_name WHERE condition;
Where are regular view results stored?
Show answerOnly the SQL definition is stored; results are calculated each time the view is queried.
Where are materialized view results stored?
Show answerResults are physically stored on disk like a real table.
When are regular views recalculated?
Show answerEvery time the view is queried, using the stored SELECT definition.
When are materialized views recalculated?
Show answerOnly during a manual or scheduled REFRESH operation, not on each query.
What does WITH CHECK OPTION do on a view?
Show answerPrevents INSERT or UPDATE operations through the view that violate the view's WHERE clause.
Syntax to drop a view?
Show answerDROP VIEW view_name;
Can a view query another view?
Show answerYes, views can be nested; one view can be based on another view.
How do you rename columns in a view?
Show answerUse AS in the SELECT clause: SELECT emp_id AS employee_number FROM employees;
Why use views to abstract table structure?
Show answerViews hide complexity, enforce consistent business logic, and simplify queries for clients.
How do views provide security?
Show answerViews expose only specific columns and rows, preventing access to sensitive data.
How do you query a view like a table?
Show answerSELECT column FROM view_name WHERE condition;
When use a view instead of a subquery?
Show answerFor frequently reused queries; views are named, stored once, and faster in many databases.

15 more cards in the app

Study this set free