First. Everything said above is good.
This addressses the question of
"how to tell if indexes are helping"
If you have built some indexes and are wondering if they are usefull, there are a couple of nice commands to be aware of..
I like to use
Code:
Set Statistics IO on
Set Statistics Time on
What statistics IO does is tell you how many "pages" were aquired and read to solve your query.
A page is an 8k grouping of rows.
The smaller the io, generally speeking the faster the query. But another very good thing to realize is that it can remove alot of locking issues, so remove overhead and issues in situations where you have more than one user.
If you run a query on a 3 gig table and don't have a good index or your criteria doesn't limit the number of rows that the query needs to examing (like a "where colX <> 1") then you will see approx 393216 pages of IO to solve the query.
Add a good index and create a query with a valid search argument and it might be resloved in as few a 3 or 5 pages of I/O.
Add a bad index and it will either not be used or you can see IO go up. THis is one reason that you should be very carefull about using "optimizer hints" to force an index use.
The Stats TIme is a little harder to read, but can be usefull in working out if the index strategy is good. It tells you info like how long did sql think about how to build the query and then execute it.. I have seen some strategys use very little IO but run slow due to the way they query executed...
Another excellent tool it the "show query Plan" option in Query Analyser..
To access this option, you would right click the query window and select "Show Execution Plan" or do a "Ctrl-K".
THis will tell you alot about the acutall indexes used and what part of the query took time. or caused sql to work harder.
Also Index type is "critical" in getting the best performance on many types of querys. Non-Clustered vrs Clustered should take some very carefull analysis (of your querys and the priority of each query - if you are low on the ground floor in index knowledge - take a good look at the "Index tuning wizard" (available via Enterprise Manager)
I tend to stay away from putting Clustered indexes on PRimary key cols as a non-clustered index is as good at finding a single record..(we don't useually do a search on a range of PK's, but due to the way you use foreign keys these are usually very good candidates for clusteed indexes)
Another goood rule is be VERY Carefull in ceating Multi COlumn Clutered inexees. The reason being the every nonclusered index also contains all the columns that exist in your clusteed index. THis can cause your databases to become HUGE##$ very fast. And actuall slow things down.
HTH
Rob