Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Non null values in Sparse columns takes extra space in SQL Server 2008

May I know why Sparse columns which are having non null values takes 4Bytes of extra space..I am finding out why it is taking 4 bytes of extra space.. Please help me out?

like image 469
Vinay Kumar Chella Avatar asked Feb 24 '26 22:02

Vinay Kumar Chella


1 Answers

From MSDN (my bold)

The SQL Server Database Engine uses the SPARSE keyword in a column definition to optimize the storage of values in that column. Therefore, when the column value is NULL for any row in the table, the values require no storage.

The reverse would be NON-null means "always store a value" = bytes used with the following condition:

Sparse columns require more storage space for nonnull values than the space required for identical data that is not marked SPARSE.

.. and the following table in MSDN shows +4 bytes per sparse column

Sorry if this sounds harsh, but what else would you expect?

And a nice summary of SPARSE here

like image 172
gbn Avatar answered Feb 27 '26 18:02

gbn