Junior From PDF SQL SQL & Databases

What is an indexed view in SQL Server?

Short answer: An indexed view (also called a materialized view) in SQL Server is a view that has a unique clustered index created on it.

Explain a bit more

This results in the view storing the query results physically in the database, similar to a table. It is useful for improving performance when you have complex queries that aggregate data, as the results of the view are precomputed and stored. Benefits: Faster read performance for complex aggregations or queries. Reduces the need for recomputing the result of a complex query each time the view is accessed. Downside: Insert, update, or delete operations on the underlying tables will incur additional overhead because the indexed view must also be updated.

Example code

CREATE VIEW employee_summary AS SELECT department, AVG(salary) AS avg_salary FROM employees GROUP BY department; - Create a clustered index on the view CREATE UNIQUE CLUSTERED INDEX idx_employee_summary ON employee_summary(department);

Real-world example (ShopNest)

ShopNest adds an index on Orders(CustomerId, CreatedAt) because “my recent orders” is queried constantly.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details