SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


basic guidelines on creating Indexes


basic guidelines on creating Indexes

Author
Message
Joy Smith San
Joy Smith San
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6116 Visits: 3200
Dear All,

Can anyone give me basic guidelines on creating Indexes...pls.


Thanks in advance.
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)

Group: General Forum Members
Points: 94253 Visits: 33010
That's a very broad topic. Here are a few of my personal pointers

1) Pick the clustered index first and pick it carefully
2) Keep the clustered index as narrow as practical (note: not as narrow as possible, narrow means smaller data types and fewer columns)
3) Usually the most frequently accessed data path is the best place for the clustered index since that's where the data is stored.
4) Create nonclustered indexes only when you know you need them. Create as few as possible and keep them as narrow as practical too.
5) Test, test, test, test, test, test
6) Test some more.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
maechismo_8514
maechismo_8514
SSCarpal Tunnel
SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)

Group: General Forum Members
Points: 4016 Visits: 2228
swmsan (3/26/2009)
Dear All,

Can anyone give me basic guidelines on creating Indexes...pls.


Thanks in advance.


Let me give a shot too:

1.) There should be atleast one clustered index for a table which should be Narrow, ever-increasing, unique
2.) Try think of creating clustered indexes on the ones which are used in range queries and the ones which are used for ORDER by clause
3.) Frequently updated columns and non-unique columns are not a good choice
4.) Non- clustered indexes when needed but be careful about the number of indexes . more number of indexes more performance overhead on your table for DML operations
5.)Think about Covering indexes to cover all the columns retrieved in your query
6.) Order of Index columns pretty important as SQL server maintains indexes only on the lading edge of the indexed columns
7.) Give consideration about fill factor too when creating indexes, inappropriate fill factor may lead to index fragmentation
GilaMonster
GilaMonster
SSC Guru
SSC Guru (213K reputation)SSC Guru (213K reputation)SSC Guru (213K reputation)SSC Guru (213K reputation)SSC Guru (213K reputation)SSC Guru (213K reputation)SSC Guru (213K reputation)SSC Guru (213K reputation)

Group: General Forum Members
Points: 213099 Visits: 46259
Krishna (3/27/2009)

1.) There should be at least one clustered index for a table which should be Narrow, ever-increasing, unique

At least one?

5.)Think about Covering indexes to cover all the columns retrieved in your query

Not all queries can be covered, not all queries should be covered. Sometimes the cons outweigh the pros. (Think of the size of a very large covering index)
6.) Order of Index columns pretty important as SQL server maintains indexes only on the lading edge of the indexed columns

I assume you mean statistics on the leading column?

There's a lot, lot more to order of columns that that. I wrote two blog posts on just that topic
http://sqlinthewild.co.za/index.php/2009/01/19/index-columns-selectivity-and-equality-predicates/
http://sqlinthewild.co.za/index.php/2009/02/06/index-columns-selectivity-and-inequality-predicates/

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

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


maechismo_8514
maechismo_8514
SSCarpal Tunnel
SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)

Group: General Forum Members
Points: 4016 Visits: 2228
GilaMonster (3/27/2009)
Krishna (3/27/2009)

1.) There should be at least one clustered index for a table which should be Narrow, ever-increasing, unique

At least one?

OMG what am I saying- only one


5.)Think about Covering indexes to cover all the columns retrieved in your query

Not all queries can be covered, not all queries should be covered. Sometimes the cons outweigh the pros. (Think of the size of a very large covering index)

Definitely not there are cons as well, but gave a basic idea


6.) Order of Index columns pretty important as SQL server maintains indexes only on the lading edge of the indexed columns

I assume you mean statistics on the leading column?

yes, ahh may be am smoking something when i was typing. :-)

thanks for pointing it out. next time should be careful while typing.....
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search