Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2017 March SQL Server Interview: The Indexed View – Frequently asked questions

SQL Server Interview: The Indexed View – Frequently asked questions

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

What is Indexed View or Materialized View?

A clustered index is the only type of SQL Server index that contains data; the clustered index on a view contains all the data that makes up the view definition. As soon as you create this clustered index, the view is materialized, meaning SQL Server allocates storage space for it which is called as Indexed view.

what happens when you create an indexed view?

The key threshold happens when you create the primary key for the view which is the unique clustered index for the view and required before you can add secondary indexes to the view.

What that does it “materializes” the view such that it is no longer just a query into your tables, but it becomes a table itself with real data. And of course, that data must be maintained to match the underlying tables.

What should be your steps for the successful implementation of indexed view?

  • Verify the SET options which are required for view and table
  • Verify that the view definition
  • Option IGNORE_DUP_KEY must be set to OFF
  • Create the view by using the WITH SCHEMABINDING option
  • Create the unique clustered index on the view
  • If GROUP BY is present, the VIEW definition must contain COUNT_BIG(*) and must not contain HAVING

Why does the first index on a view have to be CLUSTERED and UNIQUE?

It must be UNIQUE to allow easy lookup of records in the view by key value during indexed view maintenance, and to prevent creation of views with duplicates, which would require special logic to maintain. It must be clustered because only a clustered index can enforce uniqueness and store the rows at the same time.

Can we create a Non-clustered index on a View?

Yes, If your queries could benefit from having more than one index on the view, non-clustered indexes can also be created on the view.

When Indexed View updated?

The indexed view is updated after immediately update of base table.

Which commands/items can’t contain by Indexed View?

  • TOP
  • UNION
  • text, ntext, or image columns
  • DISTINCT
  • MIN, MAX, COUNT(*), COUNT(), STDEV, VARIANCE, or AVG
  • OUTER JOINs
  • Self JOINs
  • Subqueries
  • ROWSET function
  • CONTAIN or FREETEXT
  • COMPUTE or COMPUTE BY

Does indexed view affect insert performance?

Yes, it can hurt insert performance quite dramatically. Any index must be updated whenever there is a relevant change. A relevant change is any insert or delete and any update which affects a column which is in the index or is an included column for the index.

How frequently you require maintenance for indexed view?

It dependes, If underlying data is frequently updated, Indexed view requires maintainances.

Does Indexed view increase a lock contention?

Yes, It increases the lock contention.

Can we create a compressed Indexed view?

Yes, SQL Server 2016 supports on-disk storage compression for indexed views. By using indexed views compression, you can reduce the total disk storage space.

What do you know about a partition-aligned indexed view?

SQL Server 2016 supports defining indexed views on partitioned data. These views are called partition-aligned indexed views. By using these views, you can increase the speed and efficiency of your queries.

Do you know what is the use of NOEXPAND hint with the indexed view?

The NOEXPAND hint tells the optimizer to just use the index defined and to not look at the underlying tables that define the view that has been indexed. This may be necessary for some circumstances where the indexed view would work faster than letting the optimizer access the underlying tables.

Can we modify the underlying tables or columns if your view created with the WITH SCHEMABINDING option?

No, we can’t.

Mar 16, 2017Anvesh Patel
SQL Server: SET STATISTICS IO and SET STATISTICS TIME measure the Query PerformanceSQL Server: Indexed View acquires a Lock on Data
Comments: 2
  1. Moock
    July 5, 2017 at 8:45 am

    thanks that you are sharing good interviews information

  2. Jese
    July 6, 2018 at 10:24 am

    very helpful for SQL Interview Questions. Thanks

Anvesh Patel
Anvesh Patel

Database Engineer

March 16, 2017 SQL Server, SQL Server InterviewAnvesh Patel, database, database research and development, dbrnd, Indexed View, Materialized View, SQL Query, SQL Server, SQL Server Administrator, SQL Server Error, SQL Server Interview, SQL Server Monitoring, SQL Server Performance Tuning, SQL Server Programming, SQL Server Tips and Tricks, TSQL
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....