MCQs on Views and Materialized Views | PostgreSQL Database

Master PostgreSQL Views and Materialized Views by exploring their creation, management, and use cases. Learn the intricacies of materialized views, including how to refresh and utilize them efficiently.


Creating and Managing Views

  1. What is a PostgreSQL view?
    • A) A temporary table
    • B) A virtual table based on a query
    • C) A copy of a database
    • D) A database snapshot
  2. Which command is used to create a view in PostgreSQL?
    • A) CREATE TABLE
    • B) CREATE VIEW
    • C) CREATE QUERY
    • D) CREATE TABLE AS
  3. Views in PostgreSQL are updated when:
    • A) Data in the base table changes
    • B) The view is refreshed manually
    • C) They cannot reflect updated data
    • D) The database is restarted
  4. What happens if you drop a base table associated with a view?
    • A) The view remains functional
    • B) The view becomes invalid
    • C) The view updates automatically
    • D) The view converts to a table
  5. Which of the following is NOT true about views?
    • A) Views are stored as query definitions.
    • B) Views can be indexed for better performance.
    • C) Views do not store data physically.
    • D) Views can be used to simplify complex queries.
  6. How can you update data in a view in PostgreSQL?
    • A) Views are read-only by default.
    • B) Directly modify the view definition.
    • C) Insert data into the view.
    • D) Update data in the base table.
  7. Which statement is used to modify an existing view?
    • A) ALTER VIEW
    • B) UPDATE VIEW
    • C) MODIFY VIEW
    • D) CREATE OR REPLACE VIEW
  8. How can you delete a view in PostgreSQL?
    • A) DROP VIEW
    • B) DELETE VIEW
    • C) REMOVE VIEW
    • D) TRUNCATE VIEW

Use Cases for Views

  1. Why are views used in PostgreSQL?
    • A) To create indexes on large tables
    • B) To simplify complex queries
    • C) To store data physically
    • D) To replace triggers
  2. Which of the following is an example of using a view?
    • A) Hiding sensitive columns from a table
    • B) Aggregating data for reporting
    • C) Creating read-only subsets of data
    • D) All of the above
  3. How can views improve database security?
    • A) By allowing selective data access
    • B) By encrypting the underlying table
    • C) By blocking all unauthorized queries
    • D) By locking the base tables
  4. Views are best suited for:
    • A) Modifying data in base tables
    • B) Optimizing query performance
    • C) Presenting aggregated data
    • D) Storing frequently accessed data
  5. In a reporting system, views are primarily used to:
    • A) Increase data redundancy
    • B) Format data for end-user consumption
    • C) Replace indexes
    • D) Enhance database transactions
  6. What is the advantage of combining multiple tables into a single view?
    • A) Reduces storage space
    • B) Simplifies query execution for users
    • C) Makes tables read-only
    • D) Creates temporary data copies
  7. Views are NOT ideal for:
    • A) Frequently changing data
    • B) Simplifying data access
    • C) Securing sensitive data
    • D) Aggregating data for reports

Understanding Materialized Views

  1. What is a materialized view in PostgreSQL?
    • A) A temporary table stored in memory
    • B) A view that stores data physically
    • C) A snapshot of the database schema
    • D) A virtual table with live updates
  2. How does a materialized view differ from a standard view?
    • A) It requires storage space.
    • B) It is updated in real-time.
    • C) It stores query definitions only.
    • D) It cannot be indexed.
  3. Which command is used to create a materialized view in PostgreSQL?
    • A) CREATE MATERIALIZED VIEW
    • B) CREATE VIEW MATERIALIZED
    • C) CREATE TABLE VIEW
    • D) CREATE SNAPSHOT VIEW
  4. Why are materialized views used in PostgreSQL?
    • A) To enhance query performance by storing results
    • B) To replace base tables
    • C) To create dynamic data
    • D) To enforce data integrity
  5. What is the disadvantage of using materialized views?
    • A) They cannot store aggregated data.
    • B) They must be refreshed to stay updated.
    • C) They are slower than regular views.
    • D) They require a foreign key.
  6. Can a materialized view be indexed in PostgreSQL?
    • A) Yes, for faster querying
    • B) No, indexing is not allowed
    • C) Only for read-only operations
    • D) Only with a primary key
  7. When should you choose a materialized view over a standard view?
    • A) For dynamic queries
    • B) When query performance is critical
    • C) For real-time data updates
    • D) For storing raw data

Refreshing Materialized Views

  1. Which command is used to refresh a materialized view?
    • A) REFRESH MATERIALIZED VIEW
    • B) UPDATE MATERIALIZED VIEW
    • C) MODIFY MATERIALIZED VIEW
    • D) REFRESH VIEW
  2. What happens when a materialized view is refreshed?
    • A) It clears its data and reloads from the base query.
    • B) It updates only changed rows.
    • C) It deletes the view and recreates it.
    • D) It modifies the base table.
  3. How can you refresh materialized views incrementally in PostgreSQL?
    • A) Use the CONCURRENTLY option.
    • B) Perform a full refresh manually.
    • C) Add indexes to the base table.
    • D) Update the view manually.
  4. What is the advantage of the CONCURRENTLY option in refreshing materialized views?
    • A) Allows users to query the view during the refresh process.
    • B) Reduces storage requirements.
    • C) Updates the base table automatically.
    • D) Eliminates the need for indexing.
  5. Incremental refresh of materialized views works best when:
    • A) The data changes frequently.
    • B) The base query is complex.
    • C) Indexes exist on the base tables.
    • D) The materialized view has no indexes.
  6. A materialized view that is not refreshed regularly may:
    • A) Improve performance.
    • B) Show outdated data.
    • C) Cause database crashes.
    • D) Lock base tables.
  7. How do you automate the refreshing of materialized views?
    • A) By creating a database trigger
    • B) Using cron jobs or scheduled tasks
    • C) Adding an ON UPDATE rule
    • D) Writing a stored procedure
  8. Which of the following best practices applies to materialized views?
    • A) Avoid refreshing during peak usage.
    • B) Use for real-time analytics.
    • C) Keep base queries simple.
    • D) Both A and C.

Answer Key

QnoAnswer
1B) A virtual table based on a query
2B) CREATE VIEW
3A) Data in the base table changes
4B) The view becomes invalid
5B) Views can be indexed for better performance
6D) Update data in the base table
7D) CREATE OR REPLACE VIEW
8A) DROP VIEW
9B) To simplify complex queries
10D) All of the above
11A) By allowing selective data access
12C) Presenting aggregated data
13B) Format data for end-user consumption
14B) Simplifies query execution for users
15A) Frequently changing data
16B) A view that stores data physically
17A) It requires storage space
18A) CREATE MATERIALIZED VIEW
19A) To enhance query performance by storing results
20B) They must be refreshed to stay updated
21A) Yes, for faster querying
22B) When query performance is critical
23A) REFRESH MATERIALIZED VIEW
24A) It clears its data and reloads from the base query
25A) Use the CONCURRENTLY option
26A) Allows users to query the view during the refresh process
27C) Indexes exist on the base tables
28B) Show outdated data
29B) Using cron jobs or scheduled tasks
30D) Both A and C

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top