Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Index views

Author  Topic 

sreenu9f
Yak Posting Veteran

73 Posts

Posted - 2010-03-24 : 14:25:55
Hi All,
I have a question, i have some tables indexed on certain columns and these tables are huge. Views are developed on these tables for user restriction.

When the View is used in the query does it have the indexes of the base table( does that follow) or should i create new indexes on these views similar to the underline table.

Please suggest.

Thanks,

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-24 : 14:28:20
depends on query inside views and columns on which indexes are present. For indexing views, it should satisfy extra conditions like

http://www.sqlteam.com/article/indexed-views-in-sql-server-2000

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-24 : 14:30:06
Indexed views are rarely used. There is hardly ever a case to use them since the view can use the table's indexes instead.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sreenu9f
Yak Posting Veteran

73 Posts

Posted - 2010-03-24 : 14:44:41
Thanks all.

Tara-- so does the view actually uses the base table indexes when a query is run on the view?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-03-24 : 14:46:39
" does the view actually uses the base table indexes when a query is run on the view"

Yes
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-24 : 18:53:39
A view is really just a saved query. It's not until you index a view does it behave differently.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-03-25 : 04:32:44
Does it behave differently even then Tara?

Am I right in thinking that in the Enterprise Version an Index created on a View can actually be used in a query on the underlying table (if the index is relevant of course!)

In SQL 2008 are folk using Indexes on Views, or has the Filtered Index become sufficiently useful to be a suitable replacement?

We were using Indexes on Views to filter out NULLs so we could have a Unique-Index-except-for-NULLs - now we do that with a filtered index of course.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-25 : 15:44:37
Well it behaves differently in that it has indexes on it, so your storage requirements are higher plus SQL needs to keep those indexes updated too.

I haven't started using SQL2k8 yet, so I'm not sure.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -