Solved

SQL view - indexing help

Posted on 2011-03-25
7
233 Views
Last Modified: 2012-05-11
We get a datafile from a vendor which I want to use for a view and create my own "summary" columns based on multiple columns.  

CASE WHEN LEFT(Status, 2) = "EM" OR Emergency = "Y" THEN "Emergency" ELSE "Standard" END AS 'Recordstatus'

(this is somewhat simplified)

That way the users in Access can simply say "Where recordstatus = 'Emergency' " and it will pull all the necessary combinations.

My question is, should I put an index on the Emergency and the Status column - will that have an effect on the query performance?  

Should it be a combined index or should each column have a separate index?

0
Comment
Question by:Wedmore
7 Comments
 
LVL 1

Accepted Solution

by:
jesusaflores earned 500 total points
ID: 35217261
And according to your particular case, I think it's best to create it separately. however, in relation to the performance of the query, the answer is yes or no, why?, good text indexes are not desirable because the internal motors of the drivers database indexes are optimized for numeric and date type , that is why we usually do not see an index to a Boolean field, but SQL best practices indicate that if you use multiple columns in a WHERE clause, and these columns are used in many queries or Store Procedures and views should be created because here the indices the perfomaqnce is enhanced, in comparison, but what it had created.

I hope to have helped you.
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 35217904
Why not create a calculated column that handles the CASE statement and provides you with the single column with that result.  Then put that as an indexed column.
0
 

Author Comment

by:Wedmore
ID: 35217921
I always thought calculated columns should never be stored in a table.
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 22

Expert Comment

by:8080_Diver
ID: 35218056
There is a very wise bit of advise regarding databases, tables, and virtually everything else in life:
Never use "always" and always avoid using "never".

If it is the solution to your problem and, in fact, the best solution to your problem, why would you not do it?  Just to conform to an academic rule? ;-)
0
 
LVL 4

Expert Comment

by:batchakamal
ID: 35240420
Can you put the whole SELECT query to advise you better index?

Above statement is part of WHERE clause or SELECT clause?

What is your performance priority? Better data manipulation or better retrieval?

If I get these inputs then I hope that I can help you better...
0
 

Author Comment

by:Wedmore
ID: 35242189
The above statement would be part of the SELECT clause.  The real question is that since I cant index columns in a view, would indexing the columns separately or combined make a difference.

Priority is data retrieval.
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 35242372
You say that you get a data file from a vendor and, apparently, you are loading that data into a SQL Server database which you then link to from Access.  If that is the case, then why can't you add the calculated column to the SQL Server table into which you load the data file and then put an index on that calculated column?  Also, you could add multiple indexes on the SQL Server table (e.g. on Status, Emergency, and the combination of both of those columns) without even having to do the calculated column.  That should allow you to access the data, from Access, via a SQL Query.

For that matter, couldn't you put the query in a stored procedure in the SQL Server database and then execute the stored proc from your Access front end?

Pulling the data from a stored proc on SQL Server would probably be the fastest, having the data and the indexes on SQL Server would probably be next fastest.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now