According to below links, NULL
values take some storage space:
https://stackoverflow.com/questions/3731172/how-much-size-null-value-takes-in-sql-server
https://www.sqlservercentral.com/forums/topic/null-storage-2
If the column has fixed width data type - NULL
occupies the length of the column
char(10) NULL takes 10 bytes
INT NULL takes 4 bytes
If the column has variable width - NULL
takes 0 bytes
varchar(1000) NULL takes 0 bytes (+ 2 bytes of varchar column overhead ?)
Plus there is an overhead for having a nullable column. Information in links is a bit contradictory.
Can anyone shed some light on this ?
Here are my questions:
Some people say that the overhead for having nullable column is 1 bit per row, some that it is 1 byte per row
Which one is true ? I assume is 1 bit per row (so 8 rows make 1 byte), am I right ?For NULL values in varchar, there is still 2 byte overhead per row - is it actually true ?
Most important question:
I have a table with ~250 million rows of data, total size is ~115 GB
I've added 7 columns using below code, checking the size of the table using sp_spaceused after each command
added columns:
alter table MyTable add TestVarchar10 varchar(10) NULL
alter table MyTable add TestVarchar1000 varchar(1000) NULL
alter table MyTable add TestVarchar10DefaultTest varchar(10) NULL default 'test'
alter table MyTable add TestVarchar10DefaultTestWithValues varchar(10) NULL default 'test' with values
alter table MyTable add TestINT int NULL
alter table MyTable add TestINTDefault99 int NULL default 99
alter table MyTable add TestINTDefault99WithValues int NULL default 99 with values
And any of additional columns, did not increase the size of the table at all
How can this be ? I would expect table size to change as NULL
storage takes space