You can test this out for yourself with DBCC PAGE
or SQL Server internals viewer.
Some example cases are below to illustrate the following points.
- A
varchar
column that is null or empty takes up no space at all except 2 bytes in the column offset array (rows 4 and 5).
- If a variable length column is null or empty and only followed by other null/empty values none of these trailing empty columns even need the 2 bytes in the column offset array (rows 6 and 7).
- If all variable length columns are null or empty the row has no variable length section at all (rows 2 and 3).
INSERT dbo.ReferringUrl
(Id,
RequestUrl,
ReferringUrlName,
ReferringIpAddress)
VALUES (1,N'AAA','BBB','CCC'),
(2,NULL,NULL,NULL),
(3,'','',''),
(4,NULL,NULL,'CCC'),
(5,'','','CCC'),
(6,'AAA',NULL,NULL),
(7,'AAA','',''),
(8,N'AAA','BBB','CCC')
1 - All columns have values

The image above is from SQL Server internals viewer - which also helpfully provides a key for the various components in the row shown below.

2 - All varchar columns are NULL

3 - All varchar columns have empty strings

4 - All varchar columns null except final one

5 - All varchar columns empty except final one

6 - All varchar columns null except first one

7 - All varchar columns empty except first one
(due to a bug in the internals viewer this does not get the highlighting but notice it is the same length as the previous row)
