Does the physical position of FK columns matter?

  • Essentially, I'm curious if the position of an FK column matters for performance.

    That is, is:

    CREATE TABLE User (

    UserId INT IDENTITY(1,1) PRIMARY KEY,

    UserTypeId INT REFERENCES UserType(UserTypeId),

    -- 50 columns

    );

    any faster to select the UserTypes from than

    CREATE TABLE User (

    UserId INT IDENTITY(1,1) PRIMARY KEY,

    -- 50 columns

    UserTypeId INT REFERENCES UserType(UserTypeId)

    );

    Jeremiah Peschka
    Microsoft SQL Server MVP
    Managing Director - Brent Ozar PLF, LLC

  • jeremiah.peschka (10/3/2008)


    Essentially, I'm curious if the position of an FK column matters for performance.

    That is, is:

    CREATE TABLE User (

    UserId INT IDENTITY(1,1) PRIMARY KEY,

    UserTypeId INT REFERENCES UserType(UserTypeId),

    -- 50 columns

    );

    any faster to select the UserTypes from than

    CREATE TABLE User (

    UserId INT IDENTITY(1,1) PRIMARY KEY,

    -- 50 columns

    UserTypeId INT REFERENCES UserType(UserTypeId)

    );

    The location of the foreign key column in the create table statement has nothing to do with performance. By the way, the physical order of the columns on the disk is not necessarily the same as the logical order of the columns.

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • No. The declared order of columns has no effect on anything other than the order they're returned in a select * query. The order defined doesn't even define the physical storage order.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks for clarifying that for me.

    Jeremiah Peschka
    Microsoft SQL Server MVP
    Managing Director - Brent Ozar PLF, LLC

  • And, yet, we so no testing nor references to Microsoft articles on the subject... does anyone have proof one way or the other? 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply