Reputation: 5822
I have created a series of views that operate on a fairly large table. The table has been properly indexed and the performance is entirely sufficient. I would like to add an additional layer of views to the DB that are effectively views of views. What I want to know is whether SQL Server is smart enough to use the indexes on the underlying table when it builds the query, or whether I need to index the first tier of views somehow?
Upvotes: 1
Views: 831
Reputation: 36146
Yes it is. A view (not persisted) is nothing more than a query stored on your DB. If you have a view called view1 as select * from table1 and do select * from view1, SQL Server will automatically transform that to select * from table1 and then build a execution plan
Same rule applies if you increase the chain of objects adding more views.
Upvotes: 2