{"id":530,"date":"2009-08-10T07:10:00","date_gmt":"2009-08-10T07:10:00","guid":{"rendered":"\/blogs\/kimberly\/post\/Column-order-doesnt-matter-generally-but-IT-DEPENDS!.aspx"},"modified":"2013-01-11T23:07:56","modified_gmt":"2013-01-12T07:07:56","slug":"column-order-doesnt-matter-generally-but-it-depends","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/column-order-doesnt-matter-generally-but-it-depends\/","title":{"rendered":"Column order doesn&#8217;t matter&#8230; generally, but &#8211; IT DEPENDS!"},"content":{"rendered":"<p>\n<font face=\"verdana,geneva\">OK, for years I&#39;ve been saying that SQL Server doesn&#39;t care about the order in which you define the columns of your table because internally SQL Server will re-arrange your columns to store all of the fixed width columns first and the variable columns last. In both the fixed-width portion of the row as well as the variable-width portion of the row, the columns are defined in the order in which they are declared. So, what does matter?\n<\/p>\n<p>\n<font face=\"verdana,geneva\">It&#39;s all in the cost of the variable array&#39;s offset values. If the large majority of your NULLable records are at the end, then SQL Server doesn&#39;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.\n<\/p>\n<p>\nThe following script will show you how the maximum length of the row changes based on whether or not a later column in the variable block is NOT NULL &#8211; even when most\/all of the prior columns are!\n<\/p>\n<blockquote><p>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\"><font face=\"courier new,courier\">CREATE<font face=\"courier new,courier\"> <font color=\"#0000ff\"><font color=\"#0000ff\">TABLE<font face=\"courier new,courier\" size=\"3\"> RowSizeVariableBlock<br \/>\n\t<font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">(<br \/>\n\tID <font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">int <font color=\"#808080\"><font color=\"#808080\">NOT <font color=\"#808080\"><font color=\"#808080\">NULL <font color=\"#0000ff\"><font color=\"#0000ff\">identity<font color=\"#808080\"><font face=\"courier new,courier\" color=\"#808080\">,<br \/>\n\t<font face=\"courier new,courier\">c01 <font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">char<font color=\"#808080\"><font color=\"#808080\">(10<font color=\"#808080\"><font color=\"#808080\">) <font color=\"#808080\"><font color=\"#808080\">NOT <font color=\"#808080\"><font color=\"#808080\">NULL <font color=\"#0000ff\"><font color=\"#0000ff\">default <font color=\"#ff0000\"><font color=\"#ff0000\">&#39;test&#39;<font color=\"#808080\"><font face=\"courier new,courier\" color=\"#808080\">,<br \/>\n\t<font face=\"courier new,courier\">c02 <font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">datetime2<font color=\"#808080\"><font color=\"#808080\">(7<font color=\"#808080\"><font color=\"#808080\">) <font color=\"#808080\"><font color=\"#808080\">NOT <font color=\"#808080\"><font color=\"#808080\">NULL <font color=\"#0000ff\"><font color=\"#0000ff\">default <font color=\"#ff00ff\"><font color=\"#ff00ff\">sysdatetime<font color=\"#808080\"><font face=\"courier new,courier\" color=\"#808080\">(),<br \/>\n\t<font face=\"courier new,courier\">c03 <font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">char<font color=\"#808080\"><font color=\"#808080\">(80<font color=\"#808080\"><font color=\"#808080\">) <font color=\"#808080\"><font color=\"#808080\">NOT <font color=\"#808080\"><font color=\"#808080\">NULL <font color=\"#0000ff\"><font color=\"#0000ff\">default <font color=\"#ff0000\"><font color=\"#ff0000\">&#39;junk&#39;<font color=\"#808080\"><font face=\"courier new,courier\" color=\"#808080\">,<br \/>\n\t<font face=\"courier new,courier\">c04 <font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font color=\"#808080\"><font face=\"courier new,courier\" color=\"#808080\">NULL,<br \/>\n\t<font face=\"courier new,courier\">c05 <font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font color=\"#808080\"><font face=\"courier new,courier\" color=\"#808080\">NULL,<br \/>\n\t<font face=\"courier new,courier\">c06 <font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font color=\"#808080\"><font face=\"courier new,courier\" color=\"#808080\">NULL,<br \/>\n\t<font face=\"courier new,courier\">c07 <font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font color=\"#808080\"><font face=\"courier new,courier\" color=\"#808080\">NULL,<br \/>\n\t<font face=\"courier new,courier\">c08 <font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font color=\"#808080\"><font face=\"courier new,courier\" color=\"#808080\">NULL,<br \/>\n\t<font face=\"courier new,courier\">c09 <font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font color=\"#808080\"><font face=\"courier new,courier\" color=\"#808080\">NULL,<br \/>\n\t<font face=\"courier new,courier\">c10 <font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font color=\"#808080\"><font face=\"courier new,courier\" color=\"#808080\">NULL,<br \/>\n\t<font face=\"courier new,courier\">c11 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc12 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc13 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc14 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc15 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc16 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc17 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc18 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc19 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc20 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc21 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc22 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc23 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc24 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc25 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc26 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc27 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc28 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc29 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc30 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc31 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc32 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc33 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc34 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc35 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc36 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc37 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc38 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc39 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL,<br \/>\n\tc40 <font color=\"#0000ff\"><font color=\"#0000ff\">varchar<font color=\"#808080\"><font color=\"#808080\">(100<font color=\"#808080\"><font color=\"#808080\">) <font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">NULL<br \/>\n\t)<br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">go <font color=\"#0000ff\"><font color=\"#0000ff\"><\/p>\n<p>\n\t<font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">insert RowSizeVariableBlock <font color=\"#0000ff\"><font color=\"#0000ff\">DEFAULT <font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">VALUES<br \/>\n\tgo\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">select <font color=\"#808080\"><font color=\"#808080\">* <font color=\"#0000ff\"><font color=\"#0000ff\">from<font face=\"courier new,courier\" size=\"3\"> RowSizeVariableBlock <br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">go\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">select <font color=\"#808080\"><font color=\"#808080\">* <font color=\"#0000ff\"><font color=\"#0000ff\">from <font color=\"#008000\"><font color=\"#008000\">sys<font color=\"#808080\"><font color=\"#808080\">.<font face=\"courier new,courier\"><font color=\"#008000\"><font color=\"#008000\">dm_db_index_physical_stats<br \/>\n\t<font color=\"#808080\"><font color=\"#808080\">(<font color=\"#ff00ff\"><font color=\"#ff00ff\">db_id<font color=\"#808080\"><font color=\"#808080\">(), <font color=\"#ff00ff\"><font color=\"#ff00ff\">object_id<font color=\"#808080\"><font color=\"#808080\">(<font color=\"#ff0000\"><font color=\"#ff0000\">&#39;RowSizeVariableBlock&#39;<font color=\"#808080\"><font color=\"#808080\">), <font color=\"#808080\"><font color=\"#808080\">null, <font color=\"#808080\"><font color=\"#808080\">null, <font color=\"#ff0000\"><font color=\"#ff0000\">&#39;detailed&#39;<font color=\"#808080\"><font face=\"courier new,courier\" size=\"3\" color=\"#808080\">)<br \/>\n\t<font face=\"courier new,courier\"><font color=\"#008000\"><font color=\"#008000\">&#8212; review &quot;max&quot; record size = 114<br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">go\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">insert RowSizeVariableBlock<font color=\"#0000ff\"><font color=\"#0000ff\"> <font color=\"#808080\"><font color=\"#808080\">(c01<font color=\"#808080\"><font color=\"#808080\">, c03<font color=\"#808080\"><font color=\"#808080\">, c20<font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">)<br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">values <font color=\"#808080\"><font color=\"#808080\">(<font color=\"#ff0000\"><font color=\"#ff0000\">&#39;med row&#39;<font color=\"#808080\"><font color=\"#808080\">, <font color=\"#ff0000\"><font color=\"#ff0000\">&#39;up to c20&#39;<font color=\"#808080\"><font color=\"#808080\">, <font color=\"#ff0000\"><font color=\"#ff0000\">&#39;test&#39;<font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">)<br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">go\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">select <font color=\"#808080\"><font color=\"#808080\">* <font color=\"#0000ff\"><font color=\"#0000ff\">from<font face=\"courier new,courier\" size=\"3\"> RowSizeVariableBlock <br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">go\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">select <font color=\"#808080\"><font color=\"#808080\">* <font color=\"#0000ff\"><font color=\"#0000ff\">from <font color=\"#008000\"><font color=\"#008000\">sys<font color=\"#808080\"><font color=\"#808080\">.<font face=\"courier new,courier\"><font color=\"#008000\"><font color=\"#008000\">dm_db_index_physical_stats<br \/>\n\t<font color=\"#808080\"><font color=\"#808080\">(<font color=\"#ff00ff\"><font color=\"#ff00ff\">db_id<font color=\"#808080\"><font color=\"#808080\">(), <font color=\"#ff00ff\"><font color=\"#ff00ff\">object_id<font color=\"#808080\"><font color=\"#808080\">(<font color=\"#ff0000\"><font color=\"#ff0000\">&#39;RowSizeVariableBlock&#39;<font color=\"#808080\"><font color=\"#808080\">), <font color=\"#808080\"><font color=\"#808080\">null, <font color=\"#808080\"><font color=\"#808080\">null, <font color=\"#ff0000\"><font color=\"#ff0000\">&#39;detailed&#39;<font color=\"#808080\"><font face=\"courier new,courier\" size=\"3\" color=\"#808080\">)<br \/>\n\t<font face=\"courier new,courier\"><font color=\"#008000\"><font color=\"#008000\">&#8212; review &quot;max&quot; record size = 154<br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">go\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">insert RowSizeVariableBlock<font color=\"#0000ff\"><font color=\"#0000ff\"> <font color=\"#808080\"><font color=\"#808080\">(c01<font color=\"#808080\"><font color=\"#808080\">, c03<font color=\"#808080\"><font color=\"#808080\">, c30<font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">)<br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">values <font color=\"#808080\"><font color=\"#808080\">(<font color=\"#ff0000\"><font color=\"#ff0000\">&#39;med+ row&#39;<font color=\"#808080\"><font color=\"#808080\">, <font color=\"#ff0000\"><font color=\"#ff0000\">&#39;up to c30&#39;<font color=\"#808080\"><font color=\"#808080\">, <font color=\"#ff0000\"><font color=\"#ff0000\">&#39;test&#39;<font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">)<br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">go\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">select <font color=\"#808080\"><font color=\"#808080\">* <font color=\"#0000ff\"><font color=\"#0000ff\">from<font face=\"courier new,courier\" size=\"3\"> RowSizeVariableBlock <br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">go\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">select <font color=\"#808080\"><font color=\"#808080\">* <font color=\"#0000ff\"><font color=\"#0000ff\">from <font color=\"#008000\"><font color=\"#008000\">sys<font color=\"#808080\"><font color=\"#808080\">.<font face=\"courier new,courier\"><font color=\"#008000\"><font color=\"#008000\">dm_db_index_physical_stats<br \/>\n\t<font color=\"#808080\"><font color=\"#808080\">(<font color=\"#ff00ff\"><font color=\"#ff00ff\">db_id<font color=\"#808080\"><font color=\"#808080\">(), <font color=\"#ff00ff\"><font color=\"#ff00ff\">object_id<font color=\"#808080\"><font color=\"#808080\">(<font color=\"#ff0000\"><font color=\"#ff0000\">&#39;RowSizeVariableBlock&#39;<font color=\"#808080\"><font color=\"#808080\">), <font color=\"#808080\"><font color=\"#808080\">null, <font color=\"#808080\"><font color=\"#808080\">null, <font color=\"#ff0000\"><font color=\"#ff0000\">&#39;detailed&#39;<font color=\"#808080\"><font face=\"courier new,courier\" size=\"3\" color=\"#808080\">)<br \/>\n\t<font face=\"courier new,courier\"><font color=\"#008000\"><font color=\"#008000\">&#8212; review &quot;max&quot; record size = 174<br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">go\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">insert RowSizeVariableBlock<font color=\"#0000ff\"><font color=\"#0000ff\"> <font color=\"#808080\"><font color=\"#808080\">(c01<font color=\"#808080\"><font color=\"#808080\">, c03<font color=\"#808080\"><font color=\"#808080\">, c40<font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">)<br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">values <font color=\"#808080\"><font color=\"#808080\">(<font color=\"#ff0000\"><font color=\"#ff0000\">&#39;large row&#39;<font color=\"#808080\"><font color=\"#808080\">, <font color=\"#ff0000\"><font color=\"#ff0000\">&#39;up to c40&#39;<font color=\"#808080\"><font color=\"#808080\">, <font color=\"#ff0000\"><font color=\"#ff0000\">&#39;test&#39;<font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">)<br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">go\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">select <font color=\"#808080\"><font color=\"#808080\">* <font color=\"#0000ff\"><font color=\"#0000ff\">from<font face=\"courier new,courier\" size=\"3\"> RowSizeVariableBlock <br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">go\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\"><font color=\"#0000ff\"><font color=\"#0000ff\">select <font color=\"#808080\"><font color=\"#808080\">* <font color=\"#0000ff\"><font color=\"#0000ff\">from <font color=\"#008000\"><font color=\"#008000\">sys<font color=\"#808080\"><font color=\"#808080\">.<font face=\"courier new,courier\"><font color=\"#008000\"><font color=\"#008000\">dm_db_index_physical_stats<br \/>\n\t<font color=\"#808080\"><font color=\"#808080\">(<font color=\"#ff00ff\"><font color=\"#ff00ff\">db_id<font color=\"#808080\"><font color=\"#808080\">(), <font color=\"#ff00ff\"><font color=\"#ff00ff\">object_id<font color=\"#808080\"><font color=\"#808080\">(<font color=\"#ff0000\"><font color=\"#ff0000\">&#39;RowSizeVariableBlock&#39;<font color=\"#808080\"><font color=\"#808080\">), <font color=\"#808080\"><font color=\"#808080\">null, <font color=\"#808080\"><font color=\"#808080\">null, <font color=\"#ff0000\"><font color=\"#ff0000\">&#39;detailed&#39;<font face=\"courier new,courier\"><font color=\"#808080\"><font color=\"#808080\">)<br \/>\n\t<font color=\"#008000\">&#8212; review &quot;max&quot; record size = 194<br \/>\n\t<font color=\"#0000ff\"><font color=\"#0000ff\">go\n\t<\/p>\n<p>\n\t<font size=\"+0\"><font size=\"+0\"><font color=\"#000000\"><span style=\"font-family: 'Verdana','sans-serif'; font-size: 10pt\"><\/span>\n\t<\/p>\n<p>\n\t<font face=\"verdana,geneva\"><font size=\"+0\"><font size=\"+0\"><font color=\"#000000\"><span style=\"font-family: 'Verdana','sans-serif'; font-size: 10pt\">While there are some other optimizations at this level, <\/span><strong><span style=\"font-family: 'Verdana','sans-serif'; font-size: 10pt\">most<\/span><\/strong><span style=\"font-family: 'Verdana','sans-serif'; font-size: 10pt\"> tables cannot benefit from this as the data populations aren&#39;t as predictable nor are most tables filled with so many variable-width and NULLable columns.&nbsp;However, if you do have this data pattern, defining these columns at the end of your table&#39;s definition &#8211; MIGHT save a tremendous amount of space, especially when this table is very large!<\/span>\n\t<\/p>\n<p>\t<font size=\"+0\"><font size=\"+0\"><font color=\"#000000\"><span style=\"font-family: 'Verdana','sans-serif'; font-size: 10pt\"><\/span><span style=\"font-family: 'Verdana','sans-serif'; font-size: 12pt\"><\/span><font color=\"#000000\"><span style=\"font-family: 'Verdana','sans-serif'; font-size: 10pt\"><font face=\"verdana,geneva\">Paul&#39;s blogged more on these structures as well as the NULL bitmap here: <a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-null-bitmap-size\/\"><font face=\"verdana,geneva\">https:\/\/www.sqlskills.com\/blogs\/PAUL\/post\/Misconceptions-around-null-bitmap-size.aspx<\/a><font face=\"verdana,geneva\">. <\/span><span style=\"font-family: 'Verdana','sans-serif'; font-size: 12pt\"><\/span><font size=\"+0\"><font size=\"+0\"><font size=\"+0\"><font size=\"+0\"><font size=\"+0\"><font size=\"+0\"><font size=\"+0\"><font size=\"+0\"><font size=\"+0\"><font size=\"+0\"><\/p>\n<p>\n\t<font face=\"trebuchet ms,geneva\"><span style=\"line-height: 115%; font-family: 'Verdana','sans-serif'; font-size: 10pt\"><font face=\"verdana,geneva\" color=\"#000000\">Enjoy! And, thanks for reading,<br \/>\n\tkt<\/span>\n\t<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>OK, for years I&#39;ve been saying that SQL Server doesn&#39;t care about the order in which you define the columns of your table because internally SQL Server will re-arrange your columns to store all of the fixed width columns first and the variable columns last. In both the fixed-width portion of the row as well [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,37,65,66],"tags":[],"class_list":["post-530","post","type-post","status-publish","format-standard","hentry","category-design","category-inside-the-storage-engine","category-sql-server-2005","category-sql-server-2008"],"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/posts\/530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/comments?post=530"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/posts\/530\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/media?parent=530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/categories?post=530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/tags?post=530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}