Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Index usage question

Status
Not open for further replies.

jlsmithhartfiel

Programmer
Jan 7, 2002
336
US
Hello!

Ok, I think I understand the clustered vs non & single vs composite.

Now I'm working with a table that already has indexes defined. And I'm just trying to determine if I need to add another one or not. (my forte is not SQL!)

Question 1:
So, here's what exists:
INDEX Uid on Uid
CLUSTERED INDEX ix_fieldname on FieldName, TStamp

Now, at times I need to find all the records for a UID, AND FieldName AND TStamp.

Now will SQL use both the indexes above together if all 3 fields are referenced, or will I need to add another index that has all 3 fields in it?

Question 2:
2nd Table is a codes table where you look up values based on a code.
Indexes are:
UNIQUE INDEX Uid on Uid
INDEX FieldName on FieldName

When I look for a record in this table, I look for the FieldName first (which may be "counties") and then the value which is the code. To get the lable for the value.

Now, I'm a little confused because it seems the rules say that if all the records are different (where the values are for this set of FieldName), then don't add an index. Is that right? Or would I want to add another index on FieldName, Value.

Thanks in advance for any clarification! Jessica [ponytails2]
 
1. SQL Server will be able to use those indexes; it may or may not depending on what the query plan dictates to be the fastest method.

2. "It depends". How large is the table (how many rows)? How many different values of FieldName? How many different values of Value?

You might explore both the Graphical Execution Plan (in Query Analyzer) and the Index Tuning Wizard. --------------
 
Thanks for the response!

1. This makes sense.

2. The table consists of 5895 rows.
128 different FieldNames
4454 different Values

I've looked at the Execution Plan before, but to be honest, not sure what to do with the information it provides. I can see the usage percentages of the query, but not sure how to tune it from there...but...I'm running through the index tuning wizard now - thanks!
Jessica [ponytails2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top