February 14, 2007 at 10:35 am
Hi
I was wondering if whether having an index key as part of the only ky on an index or having It separately makes a difference.
i.e Create index index_test on Company (Company_ID)
Create index index_test on Company (Location_ID)
Or
Create index index_test on Company(Company_id,Location_ID)
If it doesnโt make a difference, does it make a difference as to which key comes first or is this irrelevant?
February 14, 2007 at 11:29 am
It depends. Not what you wanted to here is it? How you index a table depends on how it will be queried. If all queries are either by Company_ID only or by Company_I then Location_ID, you would want to create a single index with Company_ID first.
Indexing, however, isn't a science, its an art. One indexing scheme my improve some queries/inserts/updates/deletes, but could hamper others. You have to look at the entire system and make adjustments to benefit the whole system.
I am sure if you do a search on indexing on this site and also on http://www.sql-server-performance.com, you will find a variety of view points and guidelines for tuning a database.
February 14, 2007 at 1:28 pm
If you choose for the 2-column solution put the columns first which has the most unique values ! So it filters on top of the tree
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution ๐
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
February 15, 2007 at 3:03 am
As Lynn said, if depends on how the table is queried. If most of your queries filter on CompanyID alone, or LocationID alone, then you will want two indexes. If the most common queies are on CompanyID and LocationID then you want one index.
When you consider which column first, consider the queries. An index on CompanyID, LocationID can be used for a seek by a query filtering on CompanyID, but not for a query filtering on LocationID.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
February 15, 2007 at 3:36 am
February 15, 2007 at 8:02 am
February 15, 2007 at 8:07 am
yes.
compare it to one tree or two trees
an index has a key-part an one leaf-level containing one row for each row in the table. This row contains the key-part and the row-id or uniquified clustered index key.
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution ๐
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply