Are there any considerations to consider when designing a new table regarding the order in which columns should be declared? I first set the primary key, followed by any foreign keys (usually surrogate key integers), and then the other columns, but a discussion with a colleague made us wonder if SQL Server would populate our data, perhaps to make it faster.
Would SQL Server try and align our data on disk (with the addition) to a certain byte alignment boundary for performance reasons (the way the C ++ compiler aligned the structure in default conditions) or would it just allocate as many bytes as our shared does a row require (perhaps row-level padding)? That is, if we have a 3-byte char column and another bit / tinyint column, can we expect any changes in the behavior (better or worse) from the server, making one of them next to the other in order to align by 4 bytes ? Does SQL Server even care about what order I declare in the columns, or is it free to lay them out as I see fit?
I understand that there are probably a million things that I should first look at before trying to optimize the layout of my table columns, but for the sake of curiosity, Iโm interested in knowing if SQL Server cares about ordering the columns in general, and if so, where could to go (DMV, etc.), see how it physically puts lines on disk.
performance sql-server micro-optimization
Terence Lewis Jul 14 2018-11-11T00: 00Z
source share