Sparse Columns – code

CREATE TABLE Tabl_NonSparsed (
ID INT IDENTITY(1,1) ,
N INT,
S VARCHAR(100),
D DateTime2(7),
CONSTRAINT [PK_Tabl_NonSparsed] PRIMARY KEY CLUSTERED ([ID] ASC)
);
GO
CREATE TABLE Tabl_YesSparsed (
ID INT IDENTITY(1,1),
N INT SPARSE,
S VARCHAR(100) SPARSE,
D DateTime2(7) SPARSE,
     CONSTRAINT [PK_Tabl_YesSparsed] PRIMARY KEY CLUSTERED ([ID] ASC)
);
GO
DECLARE @i int=0;
WHILE @i < 100000 BEGIN
INSERT INTO Tabl_NonSparsed(N, S, D) VALUES (NULL, NULL, NULL);
INSERT INTO Tabl_YesSparsed(N, S, D) VALUES (NULL, NULL, NULL);
set @i += 1;
END;
GO

sp_spaceused ‘Tabl_NonSparsed‘;
Go
sp_spaceused ‘Tabl_YesSparsed‘;
GO

sparse_columns