• paulm-771594 (8/24/2010)


    I would be interested to know what the impact of using NULL is on the storage space required for a Column. i.e. does a nullable nvarchar column save space over a non-nullable nvarchar column with an empty string in it?

    If you disregard page and row compression (SQL Server 2008), SPARSE columns (also SQL 2008) and vardecimal (introduced in one of SQL Server 2005's service packs and then superceded by row compression), the short answer is:

    * For fixed length data types, there is no difference at all in storage requirements for NULL vs NOT NULL

    * For variable length data types, there is no difference in storage requirements for NULL vs NOT NULL when storing actual data values; when storing NULL values, only as much space is taken is would be needed for a zero length content.

    For instance, a varchar(20) with a string of length 5 takes 7 bytes (5 for the data; 2 for the length), whereas both the zero length string ('') and NULL take 2 bytes (0 for the data; 2 for the length).


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/