SQL Server Space Taken By Empty Strings? -
what penalty in space taken varchar
types in sql server 2012 , above? is, if have 3 columns of type nvarchar
(or varchar
matter), , empty, how space taken in table?
create table dbo.referringurl ( id int identity(1, 1) not null, requesturl nvarchar(384) collate sql_latin1_general_cp1_ci_as null, referringurlname nvarchar(384) collate sql_latin1_general_cp1_ci_as null, referringipaddress nvarchar(64) collate sql_latin1_general_cp1_ci_as null, )
you can test out dbcc page
or sql server internals viewer.
some example cases below illustrate following points.
- a
varchar
column null or empty takes no space @ except 2 bytes in column offset array (rows 4 , 5). - if variable length column null or empty , followed other null/empty values none of these trailing empty columns need 2 bytes in column offset array (rows 6 , 7).
- if variable length columns null or empty row has no variable length section @ (rows 2 , 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 - columns have values
the image above sql server internals viewer - helpfully provides key various components in row shown below.
2 - varchar columns null
3 - varchar columns have empty strings
4 - varchar columns null except final one
5 - varchar columns empty except final one
6 - varchar columns null except first one
7 - varchar columns empty except first one
(due bug in internals viewer not highlighting notice same length previous row)
Comments
Post a Comment