While messing around in SQL Server to get a better grasp on indices, I'm quite surprised to see that if I create an index (on another column than the PK) that includes all columns, it is still lighter than the clustered index.
Here for example, the clustered index is PK_Lecon
and the non clustered one IX_Lecon_AllInclude
.
The PK uses 7616 KB while the IX uses 4136 KB.
I used the "Disk Usage By Partition" report on SSMS.
What does SQL Server stores additionally in the clustered index?
The table definition:
CREATE TABLE Lecon (
LEC_Numero INT IDENTITY(1, 1) NOT NULL CONSTRAINT PK_Lecon PRIMARY KEY,
LEC_STA_Numero INT NULL,
LEC_Nom VARCHAR(50) NULL,
LEC_INT_Site INT NOT NULL CONSTRAINT DF_Lecon_LEC_INT_Site DEFAULT 2,
LEC_VAL_Numero INT NOT NULL CONSTRAINT DF_Lecon_LEC_VAL_Numero DEFAULT 1,
LEC_PrixParticipant FLOAT NULL CONSTRAINT DF_Lecon_LEC_PrixParticipant DEFAULT 0,
LEC_Status INT NOT NULL CONSTRAINT DF_Lecon_LEC_Status DEFAULT 0,
LEC_Dispenser VARCHAR(20) NOT NULL CONSTRAINT DF_Lecon_LEC_Dispenser DEFAULT 'Interne',
LEC_FCCL_ClasseID INT NULL,
LEC_Parent_Numero INT NULL,
LEC_CH_Numero INT NULL,
CONSTRAINT FK_Lecon_CadreHoraire FOREIGN KEY (LEC_CH_Numero) REFERENCES CadreHoraire (CH_Numero),
CONSTRAINT FK_Lecon_Intervenant FOREIGN KEY (LEC_INT_Site) REFERENCES Intervenant (INT_Numero),
CONSTRAINT FK_Lecon_Parent_Lecon FOREIGN KEY (LEC_Parent_Numero) REFERENCES Lecon (LEC_Numero),
CONSTRAINT FK_Lecon_Stage FOREIGN KEY (LEC_STA_Numero) REFERENCES Stage (STA_Numero),
CONSTRAINT FK_Lecon_Validite FOREIGN KEY (LEC_VAL_Numero) REFERENCES Validite (VAL_Numero)
)
And the index one:
CREATE INDEX IX_Lecon_AllInclude ON Lecon (LEC_INT_Site ASC) INCLUDE (
LEC_Numero,
LEC_STA_Numero,
LEC_Nom,
LEC_VAL_Numero,
LEC_PrixParticipant,
LEC_Status,
LEC_Dispenser,
LEC_FCCL_ClasseID,
LEC_Parent_Numero,
LEC_CH_Numero
)