SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 indexes questions
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

esthera
Flowing Fount of Yak Knowledge

1388 Posts

Posted - 09/20/2010 :  06:03:37  Show Profile  Reply with Quote
I have been playing around with indexes.
I used to think that all id identity fields were automatically indexes but I see they are not and adding the index can really speed up queries.

now my question is - up to how many indexes can you have on a table?

anything else really important to know about indexes?

RickD
Slow But Sure Yak Herding Master

United Kingdom
3608 Posts

Posted - 09/20/2010 :  06:33:43  Show Profile  Reply with Quote
you can have 1 clustered index and 999 non clustered indexes (why you'd want this many is beyond me, but they are there for you), but you do also have the include option in SQL 2005 and above.
Go to Top of Page

esthera
Flowing Fount of Yak Knowledge

1388 Posts

Posted - 09/20/2010 :  06:42:43  Show Profile  Reply with Quote
but do you gain if you keep adding non clustered indexes?
does it still make searching faster against these fields? or should you limit it to 2 or 3?
Go to Top of Page

GilaMonster
Flowing Fount of Yak Knowledge

South Africa
4507 Posts

Posted - 09/20/2010 :  06:58:25  Show Profile  Visit GilaMonster's Homepage  Reply with Quote
quote:
Originally posted by esthera

but do you gain if you keep adding non clustered indexes?


Maybe, depending on whether the indexes are useful for the queries or not.

SQL will add an index when you create primary key or unique constraints. So an identity column won't get an index, but an identity primary key will.

Indexing's nor a simple area. Some reading for you:
http://www.sqlservercentral.com/articles/Indexing/68439/ - 3 part series, read all three
http://sqlinthewild.co.za/index.php/category/sql-server/indexes/ - lots of stuff here, not necessarily in a logical order though.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3451 Posts

Posted - 09/20/2010 :  07:20:47  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
Especially note that a foreign key does *not* add a relevant index. many people assume that it does.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000