Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2004, 12:06 PM
Authorized User
 
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default Index question

In SQL Server one may create an index that goes against multiple columns. When is this to prefer over making several indexes with only one column in each?

Say I have a table containing electrical plants with the following columns (amongst others):

PlantNo varchar
CustomerID int
Startdate datetime

If I am to query for plants with a specific CustomerID and startdate, should I make one index on the two columns, or two indexes?

Anyone who can give me some guidance here?

Thanks

Gert
 
Old February 25th, 2004, 04:38 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If your are usually going to be looking for data based on three pieces of data, it would be more affective to have an index comprised of all three pieces of data. If the index can tell you exactly where to find the data for those three criteria, you will have better performance. The more specific the index, the faster the data retrieval. I can't tell you how an index performs based on how many pieces of data comprise it however. Haven't played with them that much. Perhaps there's some break even point where the overall table performance suffers from a over complicated index.

Remember something important with this: the more indexes on a table the more impact on the performance of an insert. When you insert data, an entry will be made for each index. If you are doing more selecting than inserting, it would make sense to optimize the selecting with an index. But if you are doing more inserting than selecting, be conservative with your indexes to improve insert performance.

(Jeff M, please correct me if I'm leading this thread astray.)

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old February 25th, 2004, 09:26 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

You're doing just fine ...

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old February 26th, 2004, 05:26 AM
Authorized User
 
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The table was just an example, but your answer lead me the right way. Thanks.

Gert





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Index carumuga SQL Server 2000 1 September 26th, 2008 04:10 PM
Index carumuga SQL Server 2000 1 December 31st, 2007 12:42 PM
create an index bonekrusher XSLT 5 July 31st, 2006 08:14 AM
change z-index anshul Javascript How-To 1 July 27th, 2004 03:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.