﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / Not seeing savings in sparse columns / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 17:20:31 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Not seeing savings in sparse columns</title><link>http://www.sqlservercentral.com/Forums/Topic1425940-391-1.aspx</link><description>Anytime, thanks for the feedback.</description><pubDate>Sun, 03 Mar 2013 08:54:44 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: Not seeing savings in sparse columns</title><link>http://www.sqlservercentral.com/Forums/Topic1425940-391-1.aspx</link><description>[quote][b]opc.three (3/3/2013)[/b][hr]NULL variable-length columns are returned as NULL based on the metadata of the table (and the NULL-bitmap of the record) when the result set is constructed but occupy no space on the data page.[/quote]That's very helpful. Thanks a mil!</description><pubDate>Sun, 03 Mar 2013 08:38:19 GMT</pubDate><dc:creator>winston Smith</dc:creator></item><item><title>RE: Not seeing savings in sparse columns</title><link>http://www.sqlservercentral.com/Forums/Topic1425940-391-1.aspx</link><description>NULL variable-length columns are returned as NULL based on the metadata of the table (and the NULL-bitmap of the record) when the result set is constructed but occupy no space on the data page.</description><pubDate>Sun, 03 Mar 2013 08:25:45 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: Not seeing savings in sparse columns</title><link>http://www.sqlservercentral.com/Forums/Topic1425940-391-1.aspx</link><description>Cool. Thanks for that.I have done some tests since confirming that, so char and nchar show much better savings, and int's dependant on the size of the values show a lot of savings also.But, in most applications i know, text is stored as varchar, such as in address tables etc, and this is where i thought sparse columns could help a lot as address data can be very variable, i.e some people have postal codes, some dont, some dont have a 3rd address line etc.It seems though that there is no benefit of adding sparse property to varchar fields, and there may actually be a detrimental effect. You say that there is little difference due to the way variable length col's store nulls. can you elaborate on that please?</description><pubDate>Sun, 03 Mar 2013 08:14:21 GMT</pubDate><dc:creator>winston Smith</dc:creator></item><item><title>RE: Not seeing savings in sparse columns</title><link>http://www.sqlservercentral.com/Forums/Topic1425940-391-1.aspx</link><description>Because of how NULL variable-length columns are stored you should not see a difference in your two sample tables. Try changing one of the columns to fixed-length though and you'll see a difference:[code="sql"]IF EXISTS ( SELECT  *            FROM    sys.objects            WHERE   object_id = OBJECT_ID(N'SparseColTest_NonSparse')                    AND type IN ( N'U' ) )     DROP TABLE SparseColTest_NonSparse;GOIF EXISTS ( SELECT  *            FROM    sys.objects            WHERE   object_id = OBJECT_ID(N'SparseColTest_Sparse')                    AND type IN ( N'U' ) )     DROP TABLE SparseColTest_Sparse;GOCREATE TABLE SparseColTest_NonSparse( AddressID INT IDENTITY(1, 1)               NOT NULL, [b][u]AddressLine1 INT NULL,[/u][/b] AddressLine2 VARCHAR(500) NULL, AddressLine3 VARCHAR(500) NULL, PostalCode VARCHAR(20) NULL, Country VARCHAR(50))GOCREATE TABLE SparseColTest_Sparse( AddressID INT IDENTITY(1, 1)               NOT NULL, AddressLine1 INT SPARSE                  NULL, AddressLine2 VARCHAR(500) SPARSE                           NULL, AddressLine3 VARCHAR(500) SPARSE                           NULL, PostalCode VARCHAR(20) SPARSE                        NULL, Country VARCHAR(50));GODECLARE @i INT = 100000;INSERT  INTO dbo.SparseColTest_NonSparse        (         AddressLine1,         AddressLine2,         AddressLine3,         PostalCode,         Country	                )        SELECT TOP (@i)                NULL AS AddressLine1,                NULL AS AddressLine2,                NULL AS AddressLine3,                NULL AS PostalCode,                NULL AS Country        FROM    sys.columns c1                CROSS JOIN sys.columns c2;INSERT  INTO dbo.SparseColTest_Sparse        (         AddressLine1,         AddressLine2,         AddressLine3,         PostalCode,         Country        )        SELECT TOP (@i)                NULL AS AddressLine1,                NULL AS AddressLine2,                NULL AS AddressLine3,                NULL AS PostalCode,                NULL AS Country        FROM    sys.columns c1                CROSS JOIN sys.columns c2;EXEC sp_spaceUsed     'SparseColTest_NonSparse'EXEC sp_spaceUsed     'SparseColTest_Sparse'/*name                          rows                 reserved           data               index_size         unused----------------------------- -------------------- ------------------ ------------------ ------------------ ------------------SparseColTest_NonSparse       100000               1736 KB            1688 KB            8 KB               40 KBname                          rows                 reserved           data               index_size         unused----------------------------- -------------------- ------------------ ------------------ ------------------ ------------------SparseColTest_Sparse          100000               1352 KB            1288 KB            8 KB               56 KB*/[/code]</description><pubDate>Sun, 03 Mar 2013 08:08:20 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>Not seeing savings in sparse columns</title><link>http://www.sqlservercentral.com/Forums/Topic1425940-391-1.aspx</link><description>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?[code="sql"]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 intset @i = 0while(@i &amp;lt;= 100000)BEGIN	insert into SparseColTest_NonSparse Default values	insert into SparseColTest_Sparse default values	set @i = @i + 1ENDexec 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 KBname                          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.*/[/code]</description><pubDate>Sun, 03 Mar 2013 06:23:26 GMT</pubDate><dc:creator>winston Smith</dc:creator></item></channel></rss>