Ive ran a test comparing a table with a few sparse columns to a table with no sparse columns, and i am seeing zero space saving.
I have two tables, both storing Address info mainly in varchar columns. both tables allow nulls, one has columns sparse property set.
I insert 1000 rows of default values in each (default values are null). Sparse columns store nulls differently so i believe i should see a space saving. but on running sp_spaceUsed i dont see any saving. Any ideas on what i am doing wrong or where my understanding is incorrect?
Create Table SparseColTest_NonSparse
(
AddressID int identity(1,1) not null,
AddressLine1 varchar(500) null,
AddressLine2 varchar(500) null,
AddressLine3 varchar(500) null,
PostalCode varchar(20) null,
Country varchar(50)
)
Create Table SparseColTest_Sparse
(
AddressID int identity(1,1) not null,
AddressLine1 varchar(500) sparse null,
AddressLine2 varchar(500) sparse null,
AddressLine3 varchar(500) sparse null,
PostalCode varchar(20) sparse null,
Country varchar(50)
)
declare @i int
set @i = 0
while(@i <= 100000)
BEGIN
insert into SparseColTest_NonSparse Default values
insert into SparseColTest_Sparse default values
set @i = @i + 1
END
exec sp_spaceUsed 'SparseColTest_NonSparse'
exec sp_spaceUsed 'SparseColTest_Sparse'
/*
name rows reserved data index_size unused
----------------------------- -------------------- ------------------ ------------- ----- ------------------ ------------------
SparseColTest_NonSparse 210003 2888 KB 2840 KB 8 KB 40 KB
name rows reserved data index_size unused
----------------------------- -------------------- ------------------ ------------- ----- ------------------ ------------------
SparseColTest_Sparse 210003 2888 KB 2840 KB 8 KB 40 KB
****NOTE - even with 210k rows sparse and non sparse tables are identical in size.
*/