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 2008 Forums
 SQL Server Administration (2008)
 Column Order for Primary Key
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

asqldeveloper
Starting Member

17 Posts

Posted - 08/20/2013 :  21:39:18  Show Profile  Reply with Quote
I understand that the order of columns doesnt change performance but if my primary key is made of two or more columns and its not the first columns, but spreadout in the table, would that affect index seeks or scans or affect performance. Example below.

Lets say my primarykey is OfficeName, OfficeCounty, OfficeState
and my table script is

CREATE TABLE OFFICE
(
OfficeName,
OfficeIsActive,
OfficeIsWalkableDistance,
OfficeCanBeReachedByPhone,
OfficeSupportsPrinter,
OfficeCounty,
OfficeManagerFirstName,
OfficeManagerLastName,
OfficeState
).

As you can see my primary key is spread out in the table, does it matter?

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 08/21/2013 :  00:33:27  Show Profile  Reply with Quote
the order of columns in the index do matter

see

http://weblogs.sqlteam.com/joew/archive/2008/02/13/60510.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1600 Posts

Posted - 08/22/2013 :  11:22:31  Show Profile  Reply with Quote
The order of the columns within the index does matter, as has been pointed out already. The order of those columns within the table does not (I'm not sure if that was your question or not). Moving OfficeCounty and/or OfficeState to be "earlier" in the table would have no effect on your index performance.

=================================================
The cure for anything is salt water -- sweat, tears, or the sea. -Isak Dinesen
Go to Top of Page

asqldeveloper
Starting Member

17 Posts

Posted - 08/23/2013 :  13:37:45  Show Profile  Reply with Quote
Kool

You got my question right and Thanks for answering it. Thats what I thought, but wanted to make sure. I do know that the order of index matters. Thanks.

I designed in Erwin, but I guess there is a check box which you should uncheck (and its set by default) which makes it create the table in random colum order. If you uncheck it, it would create in the exact column order you designed in Erwin.

Why on earth that it would be set to scramble by default is beyond me.
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.05 seconds. Powered By: Snitz Forums 2000