Order of columns

Chaitanya Kiran 801 Reputation points
2022-02-24T16:26:19.877+00:00

Does order of columns in table matter?

SQL Server | Other
{count} votes

Accepted answer
  1. AmeliaGu-MSFT 14,006 Reputation points Microsoft External Staff
    2022-02-25T06:04:41.937+00:00

    Hi ChaitanyaKiran-2787,

    It may depend on what columns you have. It's all in the cost of the variable array's offset values. If the large majority of your NULLable records are at the end, then SQL Server doesn't need to completely populate the variable block array (which saves 2 bytes per column). If you have a table where 36 columns are NULLable and generally they are NULL, then defining those columns at the end of the row can save you space.
    Please refer to Column order doesn’t matter… generally, but – IT DEPENDS and Does the order of columns in a table's definition matter which might be helpful.

    Best Regards,
    Amelia


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Naomi Nosonovsky 8,431 Reputation points
    2022-02-24T18:12:59.407+00:00

    Not really. It should not matter. If you use ALTER TABLE command, the new column is added at the end.

    0 comments No comments

  2. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-02-24T22:47:59.293+00:00

    If you ask me, it matters. More precisely, it matters to humans who work with the table. But it has no effect on performance, it that is what you are asking.


  3. Olaf Helper 47,436 Reputation points
    2022-02-25T07:10:39.793+00:00

    The order of columns doesn't matter from a technical point.

    If you have any preference for the order, e.g. of better readable, create a view with a column order as you like.

    0 comments No comments

  4. Viorel 122.6K Reputation points
    2022-02-25T22:08:39.41+00:00

    Some articles mention that the physical order of the fields in a row does not correspond to the order that was specified in CREATE TABLE statement. Therefore, if it is true, the physical order of columns probably matters, but the order in CREATE TABLE does not matter.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.