I am making a huge table simulating a very rough scenario in SQL (a huge table with 1024 atts, of course a lot of rows if you wonder), the data type for each attribute are floats.
To do so I am using another table which has 300 attributes and I am doing something like
SELECT [x1]
,[x2]
,[x3]
,[x4]
,[x5]
,[x6]
,[x7]
,[x8]
,[x9]
,[x10]
,[x11]
,[x12]
,[x13]
,[x14]
,[x300]
,x301= x1
,x302= x2
...
,x600= x300
,x601= x1
,x602= x2
...
,x900= x300
,x901= x1
,x902= x2
...
,x1000= x100
,x1001= x101
,x1002= x102
,x1003= x103
,x1004= x104
...
,x1024= x124
INTO test_1024
FROM my_300;
However an error is present:
Msg 1701, Level 16, State 1, Line 2
Creating or altering table 'test_1024' failed because the minimum row size
would be 8326, including 134 bytes of internal overhead. This exceeds the
maximum allowable table row size of 8060 bytes.
How to overcome this issue? (I know SQL can handle 1024 columns…)
Let’s have a look at the figures in the error message.
‘8326, including 134 bytes of internal overhead’ means that data only has taken
8326-134=8192bytes.Given that the number of columns is 1024, it’s exactly
8192÷1024=8bytes per column.Moving on to the overhead, of those 134 bytes, your 1024 columns require
1024÷8=128bytes for the NULL bitmap.As for the remaining
134-128=6bytes, I am not entirely sure but we can very well consider that size a constant overhead.Now, let’s try to estimate the maximum possible number of
floatcolumns per table in theory.The maximum row size is said to be
8060bytes.Taking off the constant overhead, it’s
8060-6=8054bytes.As we now know, one
floatcolumn takes 8 bytes of data plus 1 bit in the bitmap, which is8×8+1=65bits.The data + NULL bitmap size in bits is
8054×8=64432.The estimated maximum number of
floatcolumns per table is therefore64432÷65≈991columns.So, commenting out 33 columns in your script should result in successful creation of the table.
To verify, uncommenting one back should produce the error again.