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
 General SQL Server Forums
 New to SQL Server Programming
 Indexes

Author  Topic 

ComputerMike
Starting Member

18 Posts

Posted - 2010-03-31 : 18:39:56
We have views based on Tables with Indexes(for security). The views have no indexes. Will a select on the view use the index?

Also, could anyone comment on the use of SQL functions in the where clause of a procedure that selects from the the view (that doesn't have an index , but is based on table that does). Hope I wasn't too confusing.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-31 : 18:44:56
Queries on a view can use the indexes on the table. Indexed views are rarely used.

Your second part sounds like a very inefficient query.

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

Subscribe to my blog
Go to Top of Page

ComputerMike
Starting Member

18 Posts

Posted - 2010-03-31 : 18:48:34
I use isnull function in where claues

.....where isnull(mydate,'2050-12-31')
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-31 : 18:51:55
To see if an index gets used, simply put your query into Management Studio and select the option "Display Estimated Execution Plan" or "Include Actual Execution Plan" from the menu bar. Estimated doesn't require that the query be run, but it's only an estimate of what the plan will be. The actual plan requires that the query be run to see it.

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

Subscribe to my blog
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2010-03-31 : 21:40:52
quote:
Originally posted by ComputerMike

I use isnull function in where claues

.....where isnull(mydate,'2050-12-31')



And that will have performance implications. If you had an index on "mydate" column it would not be used. Throwing a function around a column makes the value indeterministic. So SQL Server will not use the index and will do a scan instead.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -