When defining a table, it's helpful to order the columns in logical groups and the groups themselves by purpose. The logical ordering of columns in a table conveys meaning to the developer and is an element of good style.
That is clear.
What is not clear, however, is whether the logical ordering of columns in a table has any impact on their physical ordering at the storage layer, or if it has any other impact that one might care about.
Apart from the impact on style, does column order ever matter?
There is a question on Stack Overflow about this, but it lacks an authoritative answer.
Best Answer
Does the logical ordering of columns in a table have any impact on their physical order at the storage layer? Yes.
Whether it matters or not is a different issue that I can't answer (yet).
In a similar manner to that described in the frequently linked article from Paul Randal on the anatomy of a record, let's look at a simple two column table with DBCC IND:
The output above shows that we need to look at page 89:
In the output from DBCC PAGE we see c1 stuffed with the character 'A' before c2's 'B':
And just because, lets bust open
RowStructure.mdf
with a hex editor and confirm the 'A' string preceeds the 'B' string:Now repeat the test but reverse the order of the strings, placing the 'B' characters in c1 and the 'A' characters in c2:
This time our DBCC PAGE output is different and the 'B' string appears first:
Again, just for giggles, lets check the hex dump of the data file:
As Anatomy of a Record explains, the fixed and variable length columns of a record are stored in distinct blocks. Logically interleaving fixed and variable column types has no bearing on the physical record. However, within each block the order of your columns does map to the order of bytes in the data file.
See also:
Column order doesn’t matter… generally, but – IT DEPENDS!