?
Solved

SQL view - indexing help

Posted on 2011-03-25
7
Medium Priority
?
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 1

Accepted Solution

by:
jesusaflores earned 2000 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

752 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