Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 July 14th, 2005, 11:03 AM
Authorized User
 
Join Date: Jun 2003
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question about clustered indexes

I am a newcomer to SQL Server undertaking a migration of a web site that I have written from Access 2003 to SQL Server, using ASP. I have spent a lot of time analysing the Access databases. I have also done a lot of reading, but can't find an answer to these questions:

If a table has a compound Primary Key (up to 4 rows) can you
a) make the whole primary key a clustered index?
b) make part of the key a clustered index (1 row only)
c) is there a single index for the primary key, and if so can I separately index parts of the primary key?

I appreciate how important it is to get the indexing right and I want to be absolutely clear on what I can and can't do.

Thank you
Pat Waddington

-------------------
System 3 2000 Limited
www.system3-2000.co.uk
__________________
-------------------
System 3 2000 Limited
www.system3-2000.co.uk (but very out-of-date!)
 
Old July 15th, 2005, 05:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

a) Yes, for example the OrderDetails table from Northwind db

ALTER TABLE [dbo].[Order Details] WITH NOCHECK ADD
    CONSTRAINT [PK_Order_Details] PRIMARY KEY CLUSTERED
    (
        [OrderID],
        [ProductID]
    ) ON [PRIMARY]
GO
b) NO because clustered index must be unique
c) Yes there is a single index, and Yes you can create additional indexes which only cover part of the primary key. Not sure why you'd want to though...have you noticed that SQL Server primary keys are much more flexible than Access? You don't have to have the 1st fields in the table in that order in the PK. You can have any fields in any order. You should put the most selective fields first when you create the PK (e.g. a unique value is highly selective, but a value found in half the rows is not).


This is a good article, and a good site
http://www.sql-server-performance.co..._not_equal.asp

hth
Phil





Similar Threads
Thread Thread Starter Forum Replies Last Post
Clustered Index Scan bmains SQL Server 2000 5 June 7th, 2010 11:35 AM
Page splits - Clustered vs Non-Clustered Index carumuga SQL Server 2005 3 October 20th, 2008 04:23 AM
Clustered PK Constr fails to create on big table kapluni SQL Server 2000 5 November 23rd, 2005 06:27 PM
Indexes SQ SQL Language 1 October 5th, 2004 10:24 PM
Size of Clustered Index MikeSchnell SQL Server 2000 0 May 7th, 2004 02:34 PM





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