Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

basic guidelines on creating Indexes Expand / Collapse
Author
Message
Posted Thursday, March 26, 2009 11:09 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 9:49 PM
Points: 1,507, Visits: 2,536
Dear All,

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


Thanks in advance.
Post #684771
Posted Friday, March 27, 2009 6:05 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 12:27 PM
Points: 15,541, Visits: 27,919
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 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #684939
Posted Friday, March 27, 2009 7:12 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, August 24, 2012 8:11 AM
Points: 1,097, Visits: 2,157
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

Post #685014
Posted Friday, March 27, 2009 2:05 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 12:11 PM
Points: 42,470, Visits: 35,541
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 2008, MVP
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

Post #685375
Posted Friday, March 27, 2009 2:13 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, August 24, 2012 8:11 AM
Points: 1,097, Visits: 2,157
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.....

Post #685384
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse